@predy-js/render-interface 0.3.3-beta.1 → 0.3.3-beta.3

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.1
5
+ * Version: v0.3.3-beta.3
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 {};
@@ -0,0 +1,72 @@
1
+ import type { VideoFrameFormat } from '@predy-js/specification';
2
+ /**
3
+ * video原始数据的切片,原始数据不暴露到js,只能通过decoder解析
4
+ * 只暴露当前的切片时间和是否是keyframe
5
+ */
6
+ export interface PredyVideoDecoderFrame {
7
+ time: number;
8
+ key?: boolean;
9
+ idx: number;
10
+ }
11
+ export interface PredyVideoDecoderFrameData {
12
+ width: number;
13
+ height: number;
14
+ data: Uint8Array;
15
+ idx: number;
16
+ }
17
+ export declare enum PredyVideoDecoderStatus {
18
+ init = 0,
19
+ loading = 1,
20
+ metadataReady = 2,
21
+ seekingFrame = 3,
22
+ frameReady = 4,
23
+ destroyed = 5,
24
+ error = 44
25
+ }
26
+ /**
27
+ * 视频解码的通用class,在native和web端有不同的实现
28
+ */
29
+ export interface PredyVideoDecoderMetadata {
30
+ width: number;
31
+ height: number;
32
+ duration: number;
33
+ frames: PredyVideoDecoderFrame[];
34
+ format: VideoFrameFormat;
35
+ frameBufferSize: number;
36
+ }
37
+ /**
38
+ * VideoDecoder创建参数
39
+ */
40
+ export interface PredyVideoDecoderConstructor {
41
+ name: string;
42
+ }
43
+ export type PredyVideoDecoderLoadedCallback = (error?: Error, metadata?: PredyVideoDecoderMetadata) => void;
44
+ export type PredyVideoDecoderSeekFrameCallback = (error?: Error, frame?: PredyVideoDecoderFrameData) => void;
45
+ export interface PredyVideoDecoder {
46
+ readonly name: string;
47
+ readonly status: PredyVideoDecoderStatus;
48
+ readonly metadata?: PredyVideoDecoderMetadata;
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
+ * 解析视频的下一帧,获得图像数据。
63
+ * @param frameIndex frame的index
64
+ * @param data 图像数据buffer,数据将被写入到此Buffer中,如果buffer尺寸不对,解析会失败
65
+ * @param callback 图像数据回调
66
+ */
67
+ seekFrame(frameIndex: number, data: Uint8Array, callback: PredyVideoDecoderSeekFrameCallback): void;
68
+ /**
69
+ * 释放资源
70
+ */
71
+ destroy(): void;
72
+ }
@@ -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.1",
3
+ "version": "0.3.3-beta.3",
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;
@@ -0,0 +1,82 @@
1
+ import type { VideoFrameFormat } from '@predy-js/specification';
2
+
3
+ /**
4
+ * video原始数据的切片,原始数据不暴露到js,只能通过decoder解析
5
+ * 只暴露当前的切片时间和是否是keyframe
6
+ */
7
+ export interface PredyVideoDecoderFrame {
8
+ time: number,
9
+ key?: boolean,
10
+ idx: number,
11
+ }
12
+
13
+ export interface PredyVideoDecoderFrameData {
14
+ width: number,
15
+ height: number,
16
+ data: Uint8Array,
17
+ idx: number,
18
+ }
19
+
20
+ export enum PredyVideoDecoderStatus {
21
+ init = 0, // 创建对象
22
+ loading = 1, // 正在解析metadata,解析过程任何函数调用都会导致error
23
+ metadataReady = 2, // metadata 解析完成,此时 currentFrame = -1
24
+ seekingFrame = 3, // 正在解析某一帧,解析过程任何函数调用都会导致error
25
+ frameReady = 4, // 解析某一帧完成,此时 currentFrame = frame.index
26
+ destroyed = 5, // 对象已经销毁
27
+ error = 44, // 发生错误
28
+ }
29
+
30
+ /**
31
+ * 视频解码的通用class,在native和web端有不同的实现
32
+ */
33
+ export interface PredyVideoDecoderMetadata {
34
+ width: number,
35
+ height: number,
36
+ duration: number,
37
+ frames: PredyVideoDecoderFrame[],
38
+ format: VideoFrameFormat,
39
+ frameBufferSize: number, // 每帧的buffer大小
40
+ }
41
+
42
+ /**
43
+ * VideoDecoder创建参数
44
+ */
45
+ export interface PredyVideoDecoderConstructor {
46
+ name: string,
47
+ }
48
+
49
+ export type PredyVideoDecoderLoadedCallback = (error?: Error, metadata?: PredyVideoDecoderMetadata) => void;
50
+ export type PredyVideoDecoderSeekFrameCallback = (error?: Error, frame?: PredyVideoDecoderFrameData) => void;
51
+
52
+ export interface PredyVideoDecoder {
53
+ readonly name: string,
54
+ readonly status: PredyVideoDecoderStatus,
55
+ readonly metadata?: PredyVideoDecoderMetadata,
56
+ /**
57
+ * 是否要跳播/回播,如果不需要的话,Decoder可以自行释放已经播放的帧
58
+ */
59
+ readonly willReverseTime: boolean,
60
+ readonly currentFrame: number,
61
+
62
+ /**
63
+ * 加载视频,解析视频的metadata,设置frame数组,
64
+ * 此函数只能调用一次,如果需要解析其他的视频,需要重新创建对象
65
+ * @param url 视频地址
66
+ * @param callback 解析回调
67
+ */
68
+ loadVideo(url: string, callback: PredyVideoDecoderLoadedCallback): void,
69
+
70
+ /**
71
+ * 解析视频的下一帧,获得图像数据。
72
+ * @param frameIndex frame的index
73
+ * @param data 图像数据buffer,数据将被写入到此Buffer中,如果buffer尺寸不对,解析会失败
74
+ * @param callback 图像数据回调
75
+ */
76
+ seekFrame(frameIndex: number, data: Uint8Array, callback: PredyVideoDecoderSeekFrameCallback): void,
77
+
78
+ /**
79
+ * 释放资源
80
+ */
81
+ destroy(): void,
82
+ }
@@ -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';