@predy-js/render-interface 0.3.3-beta.18 → 0.3.3-beta.19

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.18
5
+ * Version: v0.3.3-beta.19
6
6
  */
7
7
 
8
8
  // https://github.com/greggman/webgl-memory/blob/main/src/texture-utils.js
@@ -3,6 +3,8 @@ 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';
6
8
  export interface PredyRequestOptions {
7
9
  url: string;
8
10
  disableCache?: boolean;
@@ -29,8 +31,18 @@ export declare enum PredyTextEncoding {
29
31
  utf8 = 0,
30
32
  ascii = 1
31
33
  }
34
+ export declare enum PredyVideoCodec {
35
+ h264 = "avc1",
36
+ h265 = "hev1",
37
+ av1 = "av1"
38
+ }
32
39
  export interface PredyNativeInternal {
33
40
  webpDisabled?: boolean;
41
+ /**
42
+ * 是否支持获取gles3,但如果获取es3失败,会降级到es2
43
+ */
44
+ supportGLES3?: boolean;
45
+ platform: ResourcePlatform;
34
46
  createImageBitmap(data: TypedArray | string, //图片文件的数据
35
47
  options: ImageBitmapConstructor, callback: ImageBitmapCallback): void;
36
48
  getDefaultGPUCapability(): GPUCapability;
@@ -83,10 +95,20 @@ export interface PredyNativeInternal {
83
95
  */
84
96
  inflateData(data: Uint8Array, method: DataCompressMethod): Uint8Array | undefined;
85
97
  /**
86
- * 恢复当前的主JSContext,多个JSContext执行的时候会发生抢占,
87
- * 调用此函数后,当前的JSContext会被恢复
88
- */
98
+ * 恢复当前的主JSContext,多个JSContext执行的时候会发生抢占,
99
+ * 调用此函数后,当前的JSContext会被恢复
100
+ */
89
101
  restoreJSContext(): boolean;
102
+ /**
103
+ * 创建 video decoder
104
+ * @param options
105
+ */
106
+ createVideoDecoder(options: PredyVideoDecoderConstructor): PredyVideoDecoder;
107
+ /**
108
+ * 是否支持视频编码
109
+ * @param codec
110
+ */
111
+ supportVideoCodec(codec: PredyVideoCodec): boolean;
90
112
  }
91
113
  type renderSDFImageCallback = (img: SDFImage) => void;
92
114
  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,69 @@
1
+ import type { VideoFrameFormat } from '@predy-js/specification';
2
+ export interface PredyVideoDecoderFrameData {
3
+ width: number;
4
+ height: number;
5
+ data: Uint8Array;
6
+ idx: number;
7
+ }
8
+ export declare enum PredyVideoDecoderStatus {
9
+ init = 0,
10
+ loading = 1,
11
+ metadataReady = 2,
12
+ seekingFrame = 3,
13
+ frameReady = 4,
14
+ destroyed = 5,
15
+ error = 44
16
+ }
17
+ /**
18
+ * 视频解码的通用class,在native和web端有不同的实现
19
+ */
20
+ export interface PredyVideoDecoderMetadata {
21
+ width: number;
22
+ height: number;
23
+ duration: number;
24
+ frameCount: number;
25
+ format: VideoFrameFormat;
26
+ frameBufferSize: number;
27
+ }
28
+ /**
29
+ * VideoDecoder创建参数
30
+ */
31
+ export interface PredyVideoDecoderConstructor {
32
+ name: string;
33
+ prefetchOnly?: boolean;
34
+ }
35
+ export type PredyVideoDecoderLoadedCallback = (error?: Error, metadata?: PredyVideoDecoderMetadata) => void;
36
+ export type PredyVideoDecoderSeekFrameCallback = (error?: Error, frame?: PredyVideoDecoderFrameData) => void;
37
+ export interface PredyVideoDecoder {
38
+ readonly name: string;
39
+ readonly status: PredyVideoDecoderStatus;
40
+ readonly metadata?: PredyVideoDecoderMetadata;
41
+ /**
42
+ * 只做资源请求,不进行视频解码,
43
+ * 这种情况下,seekFrame永远返回error(prefetch only)
44
+ */
45
+ readonly prefetchOnly: boolean;
46
+ /**
47
+ * 是否要跳播/回播,如果不需要的话,Decoder可以自行释放已经播放的帧
48
+ */
49
+ readonly willReverseTime: boolean;
50
+ readonly currentFrame: number;
51
+ /**
52
+ * 加载视频,解析视频的metadata,设置frame数组,
53
+ * 此函数只能调用一次,如果需要解析其他的视频,需要重新创建对象
54
+ * @param url 视频地址
55
+ * @param callback 解析回调
56
+ */
57
+ loadVideo(url: string, callback: PredyVideoDecoderLoadedCallback): void;
58
+ /**
59
+ * 解析视频的下一帧,获得图像数据。如果调用的时候正在解析,callback直接返回error
60
+ * @param frameIndex frame的index
61
+ * @param data 图像数据buffer,数据将被写入到此Buffer中,如果buffer尺寸不对,解析会失败
62
+ * @param callback 图像数据回调
63
+ */
64
+ seekFrame(frameIndex: number, data: Uint8Array, callback: PredyVideoDecoderSeekFrameCallback): void;
65
+ /**
66
+ * 释放资源
67
+ */
68
+ destroy(): void;
69
+ }
@@ -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.18",
3
+ "version": "0.3.3-beta.19",
4
4
  "license": "MIT",
5
5
  "module": "./dist/index.mjs",
6
6
  "main": "./dist/index.js",
@@ -3,6 +3,8 @@ 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';
6
8
 
7
9
  export interface PredyRequestOptions {
8
10
  url: string,
@@ -42,9 +44,22 @@ export enum PredyTextEncoding {
42
44
  ascii = 1,
43
45
  }
44
46
 
47
+ export enum PredyVideoCodec {
48
+ h264 = 'avc1',
49
+ h265 = 'hev1',
50
+ av1 = 'av1'
51
+ }
52
+
45
53
  export interface PredyNativeInternal {
46
54
  webpDisabled?: boolean,
47
55
 
56
+ /**
57
+ * 是否支持获取gles3,但如果获取es3失败,会降级到es2
58
+ */
59
+ supportGLES3?: boolean,
60
+
61
+ platform: ResourcePlatform,
62
+
48
63
  createImageBitmap(data: TypedArray | string, //图片文件的数据
49
64
  options: ImageBitmapConstructor, callback: ImageBitmapCallback): void,
50
65
 
@@ -107,10 +122,22 @@ export interface PredyNativeInternal {
107
122
  inflateData(data: Uint8Array, method: DataCompressMethod): Uint8Array | undefined,
108
123
 
109
124
  /**
110
- * 恢复当前的主JSContext,多个JSContext执行的时候会发生抢占,
111
- * 调用此函数后,当前的JSContext会被恢复
112
- */
125
+ * 恢复当前的主JSContext,多个JSContext执行的时候会发生抢占,
126
+ * 调用此函数后,当前的JSContext会被恢复
127
+ */
113
128
  restoreJSContext(): boolean,
129
+
130
+ /**
131
+ * 创建 video decoder
132
+ * @param options
133
+ */
134
+ createVideoDecoder(options: PredyVideoDecoderConstructor): PredyVideoDecoder,
135
+
136
+ /**
137
+ * 是否支持视频编码
138
+ * @param codec
139
+ */
140
+ supportVideoCodec(codec: PredyVideoCodec): boolean,
114
141
  }
115
142
 
116
143
  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,79 @@
1
+ import type { VideoFrameFormat } from '@predy-js/specification';
2
+
3
+ export interface PredyVideoDecoderFrameData {
4
+ width: number,
5
+ height: number,
6
+ data: Uint8Array,
7
+ idx: number,
8
+ }
9
+
10
+ export enum PredyVideoDecoderStatus {
11
+ init = 0, // 创建对象
12
+ loading = 1, // 正在解析metadata,解析过程任何函数调用都会导致error
13
+ metadataReady = 2, // metadata 解析完成,此时 currentFrame = -1
14
+ seekingFrame = 3, // 正在解析某一帧,解析过程任何函数调用都会导致error
15
+ frameReady = 4, // 解析某一帧完成,此时 currentFrame = frame.index
16
+ destroyed = 5, // 对象已经销毁
17
+ error = 44, // 发生错误
18
+ }
19
+
20
+ /**
21
+ * 视频解码的通用class,在native和web端有不同的实现
22
+ */
23
+ export interface PredyVideoDecoderMetadata {
24
+ width: number,
25
+ height: number,
26
+ duration: number,
27
+ frameCount: number,
28
+ format: VideoFrameFormat,
29
+ frameBufferSize: number, // 每帧的buffer大小
30
+ }
31
+
32
+ /**
33
+ * VideoDecoder创建参数
34
+ */
35
+ export interface PredyVideoDecoderConstructor {
36
+ name: string,
37
+ prefetchOnly?: boolean,
38
+ }
39
+
40
+ export type PredyVideoDecoderLoadedCallback = (error?: Error, metadata?: PredyVideoDecoderMetadata) => void;
41
+ export type PredyVideoDecoderSeekFrameCallback = (error?: Error, frame?: PredyVideoDecoderFrameData) => void;
42
+
43
+ export interface PredyVideoDecoder {
44
+ readonly name: string,
45
+ readonly status: PredyVideoDecoderStatus,
46
+ readonly metadata?: PredyVideoDecoderMetadata,
47
+
48
+ /**
49
+ * 只做资源请求,不进行视频解码,
50
+ * 这种情况下,seekFrame永远返回error(prefetch only)
51
+ */
52
+ readonly prefetchOnly: boolean,
53
+ /**
54
+ * 是否要跳播/回播,如果不需要的话,Decoder可以自行释放已经播放的帧
55
+ */
56
+ readonly willReverseTime: boolean,
57
+ readonly currentFrame: number,
58
+
59
+ /**
60
+ * 加载视频,解析视频的metadata,设置frame数组,
61
+ * 此函数只能调用一次,如果需要解析其他的视频,需要重新创建对象
62
+ * @param url 视频地址
63
+ * @param callback 解析回调
64
+ */
65
+ loadVideo(url: string, callback: PredyVideoDecoderLoadedCallback): void,
66
+
67
+ /**
68
+ * 解析视频的下一帧,获得图像数据。如果调用的时候正在解析,callback直接返回error
69
+ * @param frameIndex frame的index
70
+ * @param data 图像数据buffer,数据将被写入到此Buffer中,如果buffer尺寸不对,解析会失败
71
+ * @param callback 图像数据回调
72
+ */
73
+ seekFrame(frameIndex: number, data: Uint8Array, callback: PredyVideoDecoderSeekFrameCallback): void,
74
+
75
+ /**
76
+ * 释放资源
77
+ */
78
+ destroy(): void,
79
+ }
@@ -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';