@predy-js/render-interface 0.3.3-beta.34 → 0.3.3-beta.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/statistic.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * Name: @predy-js/render-interface
3
3
  * Description: undefined
4
4
  * Author: undefined
5
- * Version: v0.3.3-beta.34
5
+ * Version: v0.3.3-beta.35
6
6
  */
7
7
 
8
8
  // https://github.com/greggman/webgl-memory/blob/main/src/texture-utils.js
@@ -4,3 +4,19 @@ export declare enum DestroyOptions {
4
4
  keep = 1,
5
5
  force = 0
6
6
  }
7
+ export declare enum PredyTextEncoding {
8
+ utf8 = 0,
9
+ ascii = 1
10
+ }
11
+ export declare enum PredyVideoCodec {
12
+ h264 = "avc1",
13
+ h265 = "hev1",
14
+ av1 = "av1"
15
+ }
16
+ export declare enum PredyResourceCacheStatus {
17
+ noCache = 0,
18
+ cached = 1,
19
+ preloaded = 2,
20
+ hitCDN = 3,
21
+ missCDN = 4
22
+ }
@@ -3,6 +3,9 @@ import type { TypedArray, vec2 } from '../type';
3
3
  import type { GPUCapability } from '../GPUCapability';
4
4
  import type { PredyResizeTemplate, SDFImageOptions, SDFImage } from '@predy-js/specification';
5
5
  import type { ImageBitmapInternal } from './ImageBitmapInternal';
6
+ import type { PredyVideoDecoder, PredyVideoDecoderConstructor } from './VideoDecoder';
7
+ import type { ResourcePlatform } from './ResourceInternal';
8
+ import type { PredyVideoCodec, PredyTextEncoding, PredyResourceCacheStatus } from '../constants';
6
9
  export interface PredyRequestOptions {
7
10
  url: string;
8
11
  disableCache?: boolean;
@@ -10,13 +13,6 @@ export interface PredyRequestOptions {
10
13
  responseType?: 'text' | 'arraybuffer';
11
14
  useSystemNetwork?: boolean;
12
15
  }
13
- export declare enum PredyResourceCacheStatus {
14
- noCache = 0,
15
- cached = 1,
16
- preloaded = 2,
17
- hitCDN = 3,
18
- missCDN = 4
19
- }
20
16
  export interface PredyRequestResponse {
21
17
  data: ArrayBuffer | string;
22
18
  cacheStatus: PredyResourceCacheStatus;
@@ -25,12 +21,13 @@ export interface PredyRequestResponse {
25
21
  export type PredyRequestCallback = (err: string | undefined, res: PredyRequestResponse) => void;
26
22
  export declare const DataCompressMethodZlib = 1;
27
23
  type DataCompressMethod = typeof DataCompressMethodZlib;
28
- export declare enum PredyTextEncoding {
29
- utf8 = 0,
30
- ascii = 1
31
- }
32
24
  export interface PredyNativeInternal {
33
25
  webpDisabled?: boolean;
26
+ /**
27
+ * 是否支持获取gles3,但如果获取es3失败,会降级到es2
28
+ */
29
+ supportGLES3?: boolean;
30
+ platform: ResourcePlatform;
34
31
  createImageBitmap(data: TypedArray | string, //图片文件的数据
35
32
  options: ImageBitmapConstructor, callback: ImageBitmapCallback): void;
36
33
  getDefaultGPUCapability(): GPUCapability;
@@ -83,10 +80,20 @@ export interface PredyNativeInternal {
83
80
  */
84
81
  inflateData(data: Uint8Array, method: DataCompressMethod): Uint8Array | undefined;
85
82
  /**
86
- * 恢复当前的主JSContext,多个JSContext执行的时候会发生抢占,
87
- * 调用此函数后,当前的JSContext会被恢复
88
- */
83
+ * 恢复当前的主JSContext,多个JSContext执行的时候会发生抢占,
84
+ * 调用此函数后,当前的JSContext会被恢复
85
+ */
89
86
  restoreJSContext(): boolean;
87
+ /**
88
+ * 创建 video decoder
89
+ * @param options
90
+ */
91
+ createVideoDecoder(options: PredyVideoDecoderConstructor): PredyVideoDecoder;
92
+ /**
93
+ * 是否支持视频编码
94
+ * @param codec
95
+ */
96
+ supportVideoCodec(codec: PredyVideoCodec): boolean;
90
97
  }
91
98
  type renderSDFImageCallback = (img: SDFImage) => void;
92
99
  export {};
@@ -23,6 +23,7 @@ export declare abstract class TextureInternal implements ResourceInternal {
23
23
  readonly height: number;
24
24
  readonly name: string;
25
25
  readonly options: TextureInternalOptions;
26
+ readonly error?: number;
26
27
  protected constructor(options: TextureInternalConstructOptions);
27
28
  abstract resize(width: number, height: number): boolean;
28
29
  abstract destroy(): void;
@@ -0,0 +1,77 @@
1
+ import type { VideoFrameFormat } from '@predy-js/specification';
2
+ import type { PredyResourceCacheStatus } from '../constants';
3
+ export interface PredyVideoDecoderFrameData {
4
+ width: number;
5
+ height: number;
6
+ data: Uint8Array;
7
+ idx: number;
8
+ keyframe: boolean;
9
+ }
10
+ export declare enum PredyVideoDecoderStatus {
11
+ init = 0,
12
+ loading = 1,
13
+ metadataReady = 2,
14
+ seekingFrame = 3,
15
+ frameReady = 4,
16
+ destroyed = 5,
17
+ error = 44
18
+ }
19
+ /**
20
+ * 视频解码的通用class,在native和web端有不同的实现
21
+ */
22
+ export interface PredyVideoDecoderMetadata {
23
+ width: number;
24
+ height: number;
25
+ duration: number;
26
+ frameCount: number;
27
+ cacheStatus: PredyResourceCacheStatus;
28
+ format: VideoFrameFormat;
29
+ frameBufferSize: number;
30
+ }
31
+ /**
32
+ * VideoDecoder创建参数
33
+ */
34
+ export interface PredyVideoDecoderConstructor {
35
+ name: string;
36
+ prefetchOnly?: boolean;
37
+ }
38
+ export type PredyVideoDecoderLoadedCallback = (error?: Error, metadata?: PredyVideoDecoderMetadata) => void;
39
+ export type PredyVideoDecoderSeekFrameCallback = (error?: Error, frame?: PredyVideoDecoderFrameData) => void;
40
+ export interface PredyVideoDecoder {
41
+ readonly name: string;
42
+ readonly status: PredyVideoDecoderStatus;
43
+ readonly metadata?: PredyVideoDecoderMetadata;
44
+ /**
45
+ * 只做资源请求,不进行视频解码,
46
+ * 这种情况下,seekFrame永远返回error(prefetch only)
47
+ */
48
+ readonly prefetchOnly: boolean;
49
+ /**
50
+ * 是否要跳播/回播,如果不需要的话,Decoder可以自行释放已经播放的帧
51
+ */
52
+ readonly willReverseTime: boolean;
53
+ readonly currentFrame: number;
54
+ /**
55
+ * 加载视频,解析视频的metadata,设置frame数组,
56
+ * 此函数只能调用一次,如果需要解析其他的视频,需要重新创建对象
57
+ * @param url 视频地址
58
+ * @param callback 解析回调
59
+ */
60
+ loadVideo(url: string, callback: PredyVideoDecoderLoadedCallback): void;
61
+ /**
62
+ * 如果当前正在解析,中断解析,并且之前的callback返回error(abort)
63
+ * 调用后回到frameReady状态
64
+ */
65
+ abortSeeking(): void;
66
+ /**
67
+ * 解析视频的下一帧,获得图像数据。如果调用的时候正在解析,callback直接返回error
68
+ * @param frameIndex frame的index
69
+ * @param data 图像数据buffer,数据将被写入到此Buffer中,如果buffer尺寸不对,解析会失败
70
+ * @param callback 图像数据回调
71
+ */
72
+ seekFrame(frameIndex: number, data: Uint8Array, callback: PredyVideoDecoderSeekFrameCallback): void;
73
+ /**
74
+ * 释放资源
75
+ */
76
+ destroy(): void;
77
+ }
@@ -13,3 +13,4 @@ export * from './TextureInternal';
13
13
  export * from './AndGLContext';
14
14
  export * from './PredyNativeInternal';
15
15
  export * from './PredyNativeModule';
16
+ export * from './VideoDecoder';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@predy-js/render-interface",
3
- "version": "0.3.3-beta.34",
3
+ "version": "0.3.3-beta.35",
4
4
  "license": "MIT",
5
5
  "module": "./dist/index.mjs",
6
6
  "main": "./dist/index.js",
@@ -5,3 +5,23 @@ export enum DestroyOptions {
5
5
  keep = 1,
6
6
  force = destroy,
7
7
  }
8
+
9
+ export enum PredyTextEncoding {
10
+ utf8 = 0,
11
+ ascii = 1,
12
+ }
13
+
14
+ export enum PredyVideoCodec {
15
+ h264 = 'avc1',
16
+ h265 = 'hev1',
17
+ av1 = 'av1'
18
+ }
19
+
20
+ export enum PredyResourceCacheStatus {
21
+ noCache = 0, // 没有缓存,走网络请求
22
+ cached = 1, // 命中缓存,如果请求同一个url,在关闭APP之前,一定会命中缓存,关闭APP后,清理时间由系统决定
23
+ preloaded = 2, // 命中预推
24
+ hitCDN = 3, // 从正常CDN加载
25
+ missCDN = 4, // CDN异常加载(回源)
26
+ }
27
+
@@ -3,6 +3,9 @@ import type { TypedArray, vec2 } from '../type';
3
3
  import type { GPUCapability } from '../GPUCapability';
4
4
  import type { PredyResizeTemplate, SDFImageOptions, SDFImage } from '@predy-js/specification';
5
5
  import type { ImageBitmapInternal } from './ImageBitmapInternal';
6
+ import type { PredyVideoDecoder, PredyVideoDecoderConstructor } from './VideoDecoder';
7
+ import type { ResourcePlatform } from './ResourceInternal';
8
+ import type { PredyVideoCodec, PredyTextEncoding, PredyResourceCacheStatus } from '../constants';
6
9
 
7
10
  export interface PredyRequestOptions {
8
11
  url: string,
@@ -17,14 +20,6 @@ export interface PredyRequestOptions {
17
20
  useSystemNetwork?: boolean,
18
21
  }
19
22
 
20
- export enum PredyResourceCacheStatus {
21
- noCache = 0, // 没有缓存,走网络请求
22
- cached = 1, // 命中缓存,如果请求同一个url,在关闭APP之前,一定会命中缓存,关闭APP后,清理时间由系统决定
23
- preloaded = 2, // 命中预推
24
- hitCDN = 3, // 从正常CDN加载
25
- missCDN = 4, // CDN异常加载(回源)
26
- }
27
-
28
23
  export interface PredyRequestResponse {
29
24
  data: ArrayBuffer | string,
30
25
  cacheStatus: PredyResourceCacheStatus,
@@ -37,28 +32,23 @@ export const DataCompressMethodZlib = 1;
37
32
 
38
33
  type DataCompressMethod = typeof DataCompressMethodZlib;
39
34
 
40
- export enum PredyTextEncoding {
41
- utf8 = 0,
42
- ascii = 1,
43
- }
44
-
45
35
  export interface PredyNativeInternal {
46
36
  webpDisabled?: boolean,
47
-
37
+ /**
38
+ * 是否支持获取gles3,但如果获取es3失败,会降级到es2
39
+ */
40
+ supportGLES3?: boolean,
41
+ platform: ResourcePlatform,
48
42
  createImageBitmap(data: TypedArray | string, //图片文件的数据
49
43
  options: ImageBitmapConstructor, callback: ImageBitmapCallback): void,
50
-
51
44
  getDefaultGPUCapability(): GPUCapability,
52
-
53
45
  requestWithCache(options: PredyRequestOptions, callback: PredyRequestCallback): void,
54
-
55
46
  /**
56
47
  * decode text from data
57
48
  * @param data
58
49
  * @param encoding 默认utf8
59
50
  */
60
51
  decodeText(data: Uint8Array, encoding?: PredyTextEncoding): string,
61
-
62
52
  /**
63
53
  * 将图片绘制到画布上,同时替换文案,绘制的顺序如下
64
54
  * 创建template.size尺寸的画布, 接下来的绘制均应用 template.offset
@@ -67,14 +57,12 @@ export interface PredyNativeInternal {
67
57
  * @param template
68
58
  */
69
59
  renderImageTemplate(template: PredyResizeTemplate): ImageBitmapInternal,
70
-
71
60
  /**
72
61
  * 异步绘制图片的模板
73
62
  * @param options
74
63
  * @param callback 如果传入callback就是异步绘制,否则会直接返回结果
75
64
  */
76
65
  generateSDFImage(options: SDFImageOptions, callback?: renderSDFImageCallback): SDFImage | undefined,
77
-
78
66
  /**
79
67
  * 下载并且执行脚本文件,此方法会缓存https的脚本内容
80
68
  * 对于http的请求(开发环境),每次都重新请求
@@ -82,7 +70,6 @@ export interface PredyNativeInternal {
82
70
  * @param callback
83
71
  */
84
72
  evaluateScriptURL(url: string, callback: (err: Error, result: any) => void): void,
85
-
86
73
  /**
87
74
  * 将float32Array转换为half float,写入Uint16Array中,
88
75
  * 如果提供了range参数,代表float16会被重新map到range中,以此提高精度范围
@@ -107,10 +94,22 @@ export interface PredyNativeInternal {
107
94
  inflateData(data: Uint8Array, method: DataCompressMethod): Uint8Array | undefined,
108
95
 
109
96
  /**
110
- * 恢复当前的主JSContext,多个JSContext执行的时候会发生抢占,
111
- * 调用此函数后,当前的JSContext会被恢复
112
- */
97
+ * 恢复当前的主JSContext,多个JSContext执行的时候会发生抢占,
98
+ * 调用此函数后,当前的JSContext会被恢复
99
+ */
113
100
  restoreJSContext(): boolean,
101
+
102
+ /**
103
+ * 创建 video decoder
104
+ * @param options
105
+ */
106
+ createVideoDecoder(options: PredyVideoDecoderConstructor): PredyVideoDecoder,
107
+
108
+ /**
109
+ * 是否支持视频编码
110
+ * @param codec
111
+ */
112
+ supportVideoCodec(codec: PredyVideoCodec): boolean,
114
113
  }
115
114
 
116
115
  type renderSDFImageCallback = (img: SDFImage) => void;
@@ -32,6 +32,8 @@ export abstract class TextureInternal implements ResourceInternal {
32
32
 
33
33
  readonly options: TextureInternalOptions;
34
34
 
35
+ readonly error?: number;
36
+
35
37
  protected constructor (options: TextureInternalConstructOptions) {
36
38
  }
37
39
 
@@ -0,0 +1,87 @@
1
+ import type { VideoFrameFormat } from '@predy-js/specification';
2
+ import type { PredyResourceCacheStatus } from '../constants';
3
+ export interface PredyVideoDecoderFrameData {
4
+ width: number,
5
+ height: number,
6
+ data: Uint8Array,
7
+ idx: number,
8
+ keyframe: boolean,
9
+ }
10
+
11
+ export enum PredyVideoDecoderStatus {
12
+ init = 0, // 创建对象
13
+ loading = 1, // 正在解析metadata,解析过程任何函数调用都会导致error
14
+ metadataReady = 2, // metadata 解析完成,此时 currentFrame = -1
15
+ seekingFrame = 3, // 正在解析某一帧,解析过程任何函数调用都会导致error
16
+ frameReady = 4, // 解析某一帧完成,此时 currentFrame = frame.index
17
+ destroyed = 5, // 对象已经销毁
18
+ error = 44, // 发生错误
19
+ }
20
+
21
+ /**
22
+ * 视频解码的通用class,在native和web端有不同的实现
23
+ */
24
+ export interface PredyVideoDecoderMetadata {
25
+ width: number,
26
+ height: number,
27
+ duration: number, // in ms
28
+ frameCount: number,
29
+ cacheStatus: PredyResourceCacheStatus,
30
+ format: VideoFrameFormat,
31
+ frameBufferSize: number, // 每帧的buffer大小
32
+ }
33
+
34
+ /**
35
+ * VideoDecoder创建参数
36
+ */
37
+ export interface PredyVideoDecoderConstructor {
38
+ name: string,
39
+ prefetchOnly?: boolean,
40
+ }
41
+
42
+ export type PredyVideoDecoderLoadedCallback = (error?: Error, metadata?: PredyVideoDecoderMetadata) => void;
43
+ export type PredyVideoDecoderSeekFrameCallback = (error?: Error, frame?: PredyVideoDecoderFrameData) => void;
44
+
45
+ export interface PredyVideoDecoder {
46
+ readonly name: string,
47
+ readonly status: PredyVideoDecoderStatus,
48
+ readonly metadata?: PredyVideoDecoderMetadata,
49
+
50
+ /**
51
+ * 只做资源请求,不进行视频解码,
52
+ * 这种情况下,seekFrame永远返回error(prefetch only)
53
+ */
54
+ readonly prefetchOnly: boolean,
55
+ /**
56
+ * 是否要跳播/回播,如果不需要的话,Decoder可以自行释放已经播放的帧
57
+ */
58
+ readonly willReverseTime: boolean,
59
+ readonly currentFrame: number,
60
+
61
+ /**
62
+ * 加载视频,解析视频的metadata,设置frame数组,
63
+ * 此函数只能调用一次,如果需要解析其他的视频,需要重新创建对象
64
+ * @param url 视频地址
65
+ * @param callback 解析回调
66
+ */
67
+ loadVideo(url: string, callback: PredyVideoDecoderLoadedCallback): void,
68
+
69
+ /**
70
+ * 如果当前正在解析,中断解析,并且之前的callback返回error(abort)
71
+ * 调用后回到frameReady状态
72
+ */
73
+ abortSeeking(): void,
74
+
75
+ /**
76
+ * 解析视频的下一帧,获得图像数据。如果调用的时候正在解析,callback直接返回error
77
+ * @param frameIndex frame的index
78
+ * @param data 图像数据buffer,数据将被写入到此Buffer中,如果buffer尺寸不对,解析会失败
79
+ * @param callback 图像数据回调
80
+ */
81
+ seekFrame(frameIndex: number, data: Uint8Array, callback: PredyVideoDecoderSeekFrameCallback): void,
82
+
83
+ /**
84
+ * 释放资源
85
+ */
86
+ destroy(): void,
87
+ }
@@ -13,3 +13,4 @@ export * from './TextureInternal';
13
13
  export * from './AndGLContext';
14
14
  export * from './PredyNativeInternal';
15
15
  export * from './PredyNativeModule';
16
+ export * from './VideoDecoder';