@predy-js/render-interface 0.3.2 → 0.3.3-beta.2

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.2
5
+ * Version: v0.3.3-beta.2
6
6
  */
7
7
 
8
8
  // https://github.com/greggman/webgl-memory/blob/main/src/texture-utils.js
@@ -3,6 +3,7 @@ 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';
6
7
  export interface PredyRequestOptions {
7
8
  url: string;
8
9
  disableCache?: boolean;
@@ -29,6 +30,10 @@ export declare enum PredyTextEncoding {
29
30
  utf8 = 0,
30
31
  ascii = 1
31
32
  }
33
+ export declare enum PredyVideoCodec {
34
+ h264 = "avc1",
35
+ h265 = "hev1"
36
+ }
32
37
  export interface PredyNativeInternal {
33
38
  webpDisabled?: boolean;
34
39
  createImageBitmap(data: TypedArray | string, //图片文件的数据
@@ -83,10 +88,20 @@ export interface PredyNativeInternal {
83
88
  */
84
89
  inflateData(data: Uint8Array, method: DataCompressMethod): Uint8Array | undefined;
85
90
  /**
86
- * 恢复当前的主JSContext,多个JSContext执行的时候会发生抢占,
87
- * 调用此函数后,当前的JSContext会被恢复
88
- */
91
+ * 恢复当前的主JSContext,多个JSContext执行的时候会发生抢占,
92
+ * 调用此函数后,当前的JSContext会被恢复
93
+ */
89
94
  restoreJSContext(): boolean;
95
+ /**
96
+ * 创建 video decoder
97
+ * @param options
98
+ */
99
+ createVideoDecoder(options: PredyVideoDecoderConstructor): PredyVideoDecoder;
100
+ /**
101
+ * 是否支持视频编码
102
+ * @param codec
103
+ */
104
+ supportVideoCodec(codec: PredyVideoCodec): boolean;
90
105
  }
91
106
  type renderSDFImageCallback = (img: SDFImage) => void;
92
107
  export {};
@@ -0,0 +1,72 @@
1
+ import type { VideoCodec } 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: VideoCodec;
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 buffer 视频数据
58
+ * @param callback 解析回调
59
+ */
60
+ loadVideo(buffer: Uint8Array | 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.2",
3
+ "version": "0.3.3-beta.2",
4
4
  "license": "MIT",
5
5
  "module": "./dist/index.mjs",
6
6
  "main": "./dist/index.js",
@@ -3,6 +3,7 @@ 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';
6
7
 
7
8
  export interface PredyRequestOptions {
8
9
  url: string,
@@ -42,6 +43,11 @@ export enum PredyTextEncoding {
42
43
  ascii = 1,
43
44
  }
44
45
 
46
+ export enum PredyVideoCodec {
47
+ h264 = 'avc1',
48
+ h265 = 'hev1',
49
+ }
50
+
45
51
  export interface PredyNativeInternal {
46
52
  webpDisabled?: boolean,
47
53
 
@@ -107,10 +113,22 @@ export interface PredyNativeInternal {
107
113
  inflateData(data: Uint8Array, method: DataCompressMethod): Uint8Array | undefined,
108
114
 
109
115
  /**
110
- * 恢复当前的主JSContext,多个JSContext执行的时候会发生抢占,
111
- * 调用此函数后,当前的JSContext会被恢复
112
- */
116
+ * 恢复当前的主JSContext,多个JSContext执行的时候会发生抢占,
117
+ * 调用此函数后,当前的JSContext会被恢复
118
+ */
113
119
  restoreJSContext(): boolean,
120
+
121
+ /**
122
+ * 创建 video decoder
123
+ * @param options
124
+ */
125
+ createVideoDecoder(options: PredyVideoDecoderConstructor): PredyVideoDecoder,
126
+
127
+ /**
128
+ * 是否支持视频编码
129
+ * @param codec
130
+ */
131
+ supportVideoCodec(codec: PredyVideoCodec): boolean,
114
132
  }
115
133
 
116
134
  type renderSDFImageCallback = (img: SDFImage) => void;
@@ -0,0 +1,82 @@
1
+ import type { VideoCodec } 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: VideoCodec,
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 buffer 视频数据
66
+ * @param callback 解析回调
67
+ */
68
+ loadVideo(buffer: Uint8Array | 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';