pr-player 0.1.9 → 0.2.1

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.
@@ -1,5 +1,4 @@
1
1
  import { RenderWorker } from './render/RenderWorker';
2
- import { Shader } from './render/type';
3
2
  interface On {
4
3
  demuxer: {
5
4
  info?: (_info: any) => void;
@@ -8,7 +7,10 @@ interface On {
8
7
  sei?: (_payload: Uint8Array) => void;
9
8
  };
10
9
  decoder: {
11
- audio?: (_AudioData: AudioData) => void;
10
+ audio?: (_audio: {
11
+ audioData: AudioData;
12
+ playbackRate?: number;
13
+ }) => void;
12
14
  video?: (_frame: {
13
15
  timestamp: number;
14
16
  bitmap: ImageBitmap;
@@ -18,6 +20,7 @@ interface On {
18
20
  }
19
21
  interface PrPlayerOption {
20
22
  debug?: boolean;
23
+ frameTrack?: boolean;
21
24
  }
22
25
  export declare class PrPlayer {
23
26
  private option;
@@ -28,9 +31,7 @@ export declare class PrPlayer {
28
31
  private decoderWorker;
29
32
  private audioPlayer;
30
33
  private renderWorker;
31
- private renderBaseTime;
32
34
  private stream;
33
- private canvas;
34
35
  on: On;
35
36
  private cutRenders;
36
37
  trackGenerator: MediaStreamTrackGenerator;
@@ -48,22 +49,41 @@ export declare class PrPlayer {
48
49
  * 停止
49
50
  */
50
51
  stop: () => Promise<void>;
51
- getCanvas: () => HTMLCanvasElement | undefined;
52
+ /**
53
+ * 获取媒体流
54
+ */
52
55
  getStream: () => MediaStream | undefined;
53
- setPause: (pause: boolean) => void;
54
56
  /**
55
- * 设置渲染模式
57
+ * 设置暂停
58
+ * @param pause: boolean
56
59
  */
57
- setShader: (shader: Shader[]) => void;
60
+ setPause: (pause: boolean) => void;
58
61
  /**
59
62
  * 是否静音 默认为true
60
63
  * @param state?: boolean
61
64
  */
62
65
  setMute: (state?: boolean) => void | undefined;
66
+ /**
67
+ * 是否开启追帧
68
+ * @param frameTrack?: boolean
69
+ */
70
+ setFrameTrack: (frameTrack: boolean) => void;
63
71
  /**
64
72
  * 是否已准备好
65
73
  */
66
74
  isReady: () => Promise<unknown>;
75
+ /**
76
+ * 初始化解复器
77
+ */
78
+ private initDemuxer;
79
+ /**
80
+ * 初始化解码器
81
+ */
82
+ private initDecoder;
83
+ /**
84
+ * 初始化渲染器
85
+ */
86
+ private initRender;
67
87
  cut: {
68
88
  /**
69
89
  * 创建剪切
@@ -76,33 +96,22 @@ export declare class PrPlayer {
76
96
  }) => {
77
97
  worker: RenderWorker;
78
98
  stream: MediaStream;
79
- canvas: HTMLCanvasElement;
80
99
  destroy: Function;
81
100
  };
82
- getCanvas: (key: string) => HTMLCanvasElement | undefined;
101
+ /**
102
+ * 获取媒体流
103
+ */
83
104
  getStream: (key: string) => MediaStream | undefined;
84
- setPause: (key: string, pause: boolean) => void;
85
105
  /**
86
- * 设置渲染模式
106
+ * 设置暂停
107
+ * @param pause: boolean
87
108
  */
88
- setShader: (key: string, shader: Shader[]) => void;
109
+ setPause: (key: string, pause: boolean) => void;
89
110
  /**
90
111
  * 移除剪切
91
112
  */
92
113
  remove: (key: string) => void;
93
114
  };
94
- /**
95
- * 初始化解复器
96
- */
97
- private initDemuxer;
98
- /**
99
- * 初始化解码器
100
- */
101
- private initDecoder;
102
- /**
103
- * 初始化渲染器
104
- */
105
- private initRender;
106
115
  private flv;
107
116
  private hls;
108
117
  }
@@ -8,7 +8,10 @@ export declare class AudioPlayer {
8
8
  pendingSources: AudioBufferSourceNode[];
9
9
  constructor();
10
10
  init: (audioContext?: AudioContext) => void;
11
- push(audioData: AudioData): Promise<void>;
11
+ push(audio: {
12
+ audioData: AudioData;
13
+ playbackRate?: number;
14
+ }): Promise<void>;
12
15
  getStream: () => MediaStream | undefined;
13
16
  destroy(): void;
14
17
  }
@@ -5,17 +5,38 @@ export declare class Decoder {
5
5
  private videoDecoderConfig?;
6
6
  private videoDecoder?;
7
7
  private hasKeyFrame;
8
+ private baseTime;
9
+ private pendingChunks;
10
+ private isProcessing;
11
+ private decodeTimer;
12
+ private frameTrack;
13
+ private minFrameTrackCacheNum;
14
+ private decodingSpeed;
15
+ private decodingSpeedRatio;
16
+ private maxDecodingSpeedRatio;
17
+ private nextRenderTime?;
8
18
  on: On;
9
19
  constructor();
20
+ init: (option: {
21
+ decodingSpeed: number;
22
+ frameTrack?: boolean;
23
+ minFrameTrackCacheNum?: number;
24
+ }) => void;
25
+ setFrameTrack: (frameTrack: boolean) => void;
26
+ private initDecodeInterval;
27
+ private decode;
28
+ private decodeAudio;
29
+ private decodeVideo;
30
+ destroy: () => void;
10
31
  audio: {
11
32
  init: (config: AudioDecoderConfig) => void;
12
- decode: (init: EncodedAudioChunkInit) => void;
33
+ push: (init: EncodedAudioChunkInit) => void;
13
34
  flush: () => void;
14
35
  destroy: () => void;
15
36
  };
16
37
  video: {
17
38
  init: (config: VideoDecoderConfig) => void;
18
- decode: (init: EncodedVideoChunkInit) => void;
39
+ push: (init: EncodedVideoChunkInit) => void;
19
40
  flush: () => void;
20
41
  destroy: () => void;
21
42
  };
@@ -3,15 +3,21 @@ export declare class DecoderWorker {
3
3
  worker: Worker;
4
4
  on: On;
5
5
  constructor();
6
+ init: (option: {
7
+ decodingSpeed: number;
8
+ frameTrack?: boolean;
9
+ minFrameTrackCacheNum?: number;
10
+ }) => void;
11
+ setFrameTrack: (frameTrack: boolean) => void;
6
12
  audio: {
7
13
  init: (config: AudioDecoderConfig) => void;
8
- decode: (init: EncodedAudioChunkInit) => void;
14
+ push: (init: EncodedAudioChunkInit) => void;
9
15
  flush: () => void;
10
16
  destroy: () => void;
11
17
  };
12
18
  video: {
13
19
  init: (config: VideoDecoderConfig) => void;
14
- decode: (init: EncodedVideoChunkInit) => void;
20
+ push: (init: EncodedVideoChunkInit) => void;
15
21
  flush: () => void;
16
22
  destroy: () => void;
17
23
  };
@@ -1,6 +1,9 @@
1
1
  export interface On {
2
2
  audio: {
3
- decode?: (_audioData: AudioData) => void;
3
+ decode?: (_audio: {
4
+ audioData: AudioData;
5
+ playbackRate?: number;
6
+ }) => void;
4
7
  error?: (_e: DOMException) => void;
5
8
  };
6
9
  video: {
@@ -11,3 +14,13 @@ export interface On {
11
14
  error?: (_e: DOMException) => void;
12
15
  };
13
16
  }
17
+ interface PendingAudioChunk {
18
+ type: 'audio';
19
+ init: EncodedAudioChunkInit;
20
+ }
21
+ interface PendingVideoChunk {
22
+ type: 'video';
23
+ init: EncodedAudioChunkInit;
24
+ }
25
+ export type PendingChunk = PendingAudioChunk | PendingVideoChunk;
26
+ export {};
@@ -1,4 +1,4 @@
1
- import { Cacher, Chunk } from '../cacher/Cacher';
1
+ import { Cacher, Chunk } from './Cacher';
2
2
  export type Pattern = 'hls' | 'dash' | 'rtmp' | 'flv';
3
3
  export interface AudioConfig {
4
4
  kind: 'audio';
@@ -1,4 +1,4 @@
1
- import { Chunk } from '../cacher/Cacher';
1
+ import { Chunk } from './Cacher';
2
2
  import { AudioConfig, VideoConfig } from './Demuxer';
3
3
  export interface On {
4
4
  debug?: (_debug: any) => void;
@@ -1,4 +1,4 @@
1
- import { Chunk } from '../cacher/Cacher';
1
+ import { Chunk } from './Cacher';
2
2
  import { AudioConfig, VideoConfig } from './Demuxer';
3
3
  export interface Pat {
4
4
  header: {