Browse Source

使用compostionTime延迟播放For B 帧

worker
李宇翔 6 years ago
parent
commit
53a1de8993
  1. 4
      Jessibuca.js
  2. 7
      VideoDecoder.h
  3. 3
      libhevc.h
  4. 16
      make.py
  5. 1
      public/ff_wasm.js
  6. BIN
      public/ff_wasm.wasm
  7. 20
      public/hevc.js
  8. 13
      public/renderer.js

4
Jessibuca.js

@ -152,7 +152,7 @@ mergeInto(LibraryManager.library, {
this.buffers = [[], [], []]
var size = w * h
if (this.isWebGL) {
this.draw = function () {
this.draw = function (compositionTime) {
var y = HEAPU32[dataPtr];
var u = HEAPU32[dataPtr + 1];
var v = HEAPU32[dataPtr + 2];
@ -160,7 +160,7 @@ mergeInto(LibraryManager.library, {
var outputArray = [HEAPU8.subarray(y, y + size), HEAPU8.subarray(u, u + (size >> 2)), HEAPU8.subarray(v, v + (size >> 2))];
this.setBuffer(outputArray)
// var outputArray = [new Uint8Array(this.buffer, 0, size), new Uint8Array(this.buffer, size, size >> 2), new Uint8Array(this.buffer, size + (size >> 2), size >> 2)]
postMessage({ cmd: "render", output: outputArray }, [outputArray[0].buffer, outputArray[1].buffer, outputArray[2].buffer])
postMessage({ cmd: "render", output: outputArray, compositionTime: compositionTime }, [outputArray[0].buffer, outputArray[1].buffer, outputArray[2].buffer])
};
} else {
var outputArray = HEAPU8.subarray(dataPtr, dataPtr + (w * h << 2));

7
VideoDecoder.h

@ -21,7 +21,7 @@ public:
u32 p_yuv[3];
int NAL_unit_length;
bool webgl;
u32 compositionTime;
VideoDecoder() : heap(nullptr), webgl(false), NAL_unit_length(0), videoWidth(0), videoHeight(0)
{
}
@ -67,7 +67,7 @@ public:
{
yuv420toRGB((u8 *)p_yuv[0], (u8 *)p_yuv[1], (u8 *)p_yuv[2], heap, videoWidth, videoHeight);
}
jsObject->call<void>("draw");
jsObject->call<void>("draw", compositionTime);
}
virtual void decodeH264Header(IOBuffer &data)
@ -135,7 +135,8 @@ public:
}
else
{
data >>= 5;
data >>= 2;
compositionTime = data.readUInt24B();
decodeBody(data);
}
}

3
libhevc.h

@ -84,18 +84,21 @@ public:
s_video_decode_ip.pv_stream_buffer = (void *)data.point();
s_video_decode_ip.u4_num_Bytes = vps;
EXECUTE(&s_video_decode_ip, &s_video_decode_op, "\nError in header vps decode %x", s_video_decode_op.u4_error_code)
//emscripten_log(0, "vps %d", s_video_decode_op.u4_num_bytes_consumed);
data >>= vps;
data >>= 3;
data.read2B(sps);
s_video_decode_ip.pv_stream_buffer = (void *)data.point();
s_video_decode_ip.u4_num_Bytes = sps;
EXECUTE(&s_video_decode_ip, &s_video_decode_op, "\nError in header sps decode %x", s_video_decode_op.u4_error_code)
//emscripten_log(0, "sps %d", s_video_decode_op.u4_num_bytes_consumed);
data >>= sps;
data >>= 3;
data.read2B(pps);
s_video_decode_ip.pv_stream_buffer = (void *)data.point();
s_video_decode_ip.u4_num_Bytes = pps;
EXECUTE(&s_video_decode_ip, &s_video_decode_op, "\nError in header pps decode %x", s_video_decode_op.u4_error_code)
//emscripten_log(0, "pps %d", s_video_decode_op.u4_num_bytes_consumed);
decodeVideoSize(s_video_decode_op.u4_pic_wd, s_video_decode_op.u4_pic_ht);
CALL_API(ivd_ctl_set_config, "\nError in setting the codec in frame decode mode", IVD_CMD_VIDEO_CTL, IVD_CMD_CTL_SETPARAMS, IVD_DECODE_FRAME, STRIDE, IVD_SKIP_NONE, IVD_DISPLAY_FRAME_OUT)
s_video_decode_ip.s_out_buffer.u4_num_bufs = 3;

16
make.py

@ -11,15 +11,15 @@ import getopt
from subprocess import Popen, PIPE, STDOUT
exec(open(os.path.expanduser('~/.emscripten'), 'r').read())
# sys.path.append(EMSCRIPTEN_ROOT)
opts, args = getopt.getopt(sys.argv[1:], "v:a:o:", [
"wasm", "disable-audio", 'cocos'])
args = {'-a': 'mp3', '-o': 'public/Jessibuca.js'}
opts, args = getopt.getopt(sys.argv[1:], "v:a:o:", ["wasm", 'cocos'])
args = {'-o': 'public/Jessibuca.js'}
for op, value in opts:
if value == 'ff':
value = 'ffmpeg'
args[op] = value
video_codec = '-DUSE_'+(args['-v']).upper() if '-v' in args else ''
audio_codec = '' if '--disable-audio' in args else '-DUSE_' + \
(args['-a']).upper()
audio_codec = '-DUSE_'+(args['-a']).upper() if '-a' in args else ''
sargs = {
# 'USE_PTHREADS': 0 if '--cocos' in args else 1,
'WASM': 1 if '--wasm' in args else 0,
@ -27,7 +27,7 @@ sargs = {
'ASSERTIONS': 0,
'NO_EXIT_RUNTIME': 1,
'ERROR_ON_UNDEFINED_SYMBOLS': 0,
'DISABLE_EXCEPTION_CATCHING':1
'DISABLE_EXCEPTION_CATCHING': 1
# 'INVOKE_RUN':1
# 'DEMANGLE_SUPPORT':1
}
@ -68,9 +68,7 @@ if audio_codec == '-DUSE_AAC':
elif audio_codec == '-DUSE_SPEEX':
emcc_args.append('-Ithirdparty/speex-1.2rc2/include')
object_files.append('libspeex.bc')
elif '--disable-audio' in args:
print 'disable-audio'
else:
elif audio_codec == '-DUSE_MP3':
object_files.append('mp3.bc')
print object_files
# emscripten.Building.emcc('Jessibuca.cpp', [os.path.join(

1
public/ff_wasm.js
File diff suppressed because it is too large
View File

BIN
public/ff_wasm.wasm

20
public/hevc.js
File diff suppressed because it is too large
View File

13
public/renderer.js

@ -1,5 +1,3 @@
function Jessibuca(opt) {
this.canvasElement = opt.canvas;
this.contextOptions = opt.contextOptions;
@ -13,6 +11,10 @@ function Jessibuca(opt) {
};
this.decoderWorker = new Worker(opt.decoder || '264_mp3.js')
var _this = this
function draw(output) {
_this.drawNextOutputPicture(_this.width, _this.height, null, output)
postMessage({ cmd: "setBuffer", buffer: output }, '*', [output[0].buffer, output[1].buffer, output[2].buffer])
}
this.decoderWorker.onmessage = function (event) {
var msg = event.data
switch (msg.cmd) {
@ -40,8 +42,11 @@ function Jessibuca(opt) {
_this.onPlay()
delete _this.onPlay;
}
_this.drawNextOutputPicture(_this.width, _this.height, null, msg.output)
postMessage({ cmd: "setBuffer", buffer: msg.output }, '*', [msg.output[0].buffer, msg.output[1].buffer, msg.output[2].buffer])
if (msg.compositionTime) {
setTimeout(draw, msg.compositionTime, msg.output)
} else {
draw(msg.output)
}
break
case "initAudio":
_this.initAudioPlay(msg.frameCount, msg.samplerate, msg.channels)

Loading…
Cancel
Save