summaryrefslogtreecommitdiffstats
path: root/libmpcodecs/ve_x264.c
diff options
context:
space:
mode:
authorUoti Urpala <uau@glyph.nonexistent.invalid>2009-10-06 04:28:59 +0300
committerUoti Urpala <uau@glyph.nonexistent.invalid>2009-10-06 04:48:00 +0300
commit7fd3eb0f74e7986e07556077ed654bad7869add8 (patch)
tree8d293145c0ef2bc31ca63f79dccb4e3b57294c82 /libmpcodecs/ve_x264.c
parentef438b3a6b5bc714d521dd46d3ccb798ecd31eed (diff)
parentcbbc886820e981f488660708678f528e1d243121 (diff)
downloadmpv-7fd3eb0f74e7986e07556077ed654bad7869add8.tar.bz2
mpv-7fd3eb0f74e7986e07556077ed654bad7869add8.tar.xz
Merge svn changes up to r29752
As part of merging subtitle-in-terminal changes make update_subtitles() only clear existing subtitles if called with the reset argument, and not try to set new ones. Later calls should set the needed new subtitles, and this change avoids some problems with trying to set subtitles when mp_property_sub() in command.c gets called from initialization code before full initialization.
Diffstat (limited to 'libmpcodecs/ve_x264.c')
-rw-r--r--libmpcodecs/ve_x264.c47
1 files changed, 10 insertions, 37 deletions
diff --git a/libmpcodecs/ve_x264.c b/libmpcodecs/ve_x264.c
index 3a909cdfb7..6733b8c641 100644
--- a/libmpcodecs/ve_x264.c
+++ b/libmpcodecs/ve_x264.c
@@ -59,20 +59,6 @@ static int turbo = 0;
static x264_param_t param;
static int parse_error = 0;
-static int encode_nals(uint8_t *buf, int size, x264_nal_t *nals, int nnal){
- uint8_t *p = buf;
- int i;
-
- for(i = 0; i < nnal; i++){
- int s = x264_nal_encode(p, &size, 1, nals + i);
- if(s < 0)
- return -1;
- p += s;
- }
-
- return p - buf;
-}
-
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts);
static int encode_frame(struct vf_instance *vf, x264_picture_t *pic_in);
@@ -189,21 +175,13 @@ static int config(struct vf_instance* vf, int width, int height, int d_width, in
}
if(!param.b_repeat_headers){
- uint8_t *extradata;
x264_nal_t *nal;
- int extradata_size, nnal, i, s = 0;
+ int extradata_size, nnal;
- x264_encoder_headers(mod->x264, &nal, &nnal);
-
- /* 5 bytes NAL header + worst case escaping */
- for(i = 0; i < nnal; i++)
- s += 5 + nal[i].i_payload * 4 / 3;
-
- extradata = malloc(s);
- extradata_size = encode_nals(extradata, s, nal, nnal);
+ extradata_size = x264_encoder_headers(mod->x264, &nal, &nnal);
mod->mux->bih= realloc(mod->mux->bih, sizeof(BITMAPINFOHEADER) + extradata_size);
- memcpy(mod->mux->bih + 1, extradata, extradata_size);
+ memcpy(mod->mux->bih + 1, nal->p_payload, extradata_size);
mod->mux->bih->biSize= sizeof(BITMAPINFOHEADER) + extradata_size;
}
@@ -218,12 +196,10 @@ static int config(struct vf_instance* vf, int width, int height, int d_width, in
static int control(struct vf_instance* vf, int request, void *data)
{
h264_module_t *mod=(h264_module_t*)vf->priv;
- int count = 256; // giant HACK, x264_encoder_encode may incorrectly return 0
- // when threads > 1 and delayed frames pending
switch(request){
case VFCTRL_FLUSH_FRAMES:
- while(encode_frame(vf, NULL) == 0 && --count);
- while(encode_frame(vf, NULL) > 0);
+ while (x264_encoder_delayed_frames(mod->x264) > 0)
+ encode_frame(vf, NULL);
return CONTROL_TRUE;
default:
return CONTROL_UNKNOWN;
@@ -273,23 +249,20 @@ static int encode_frame(struct vf_instance *vf, x264_picture_t *pic_in)
x264_picture_t pic_out;
x264_nal_t *nal;
int i_nal;
- int i_size = 0;
- int i;
+ int i_size;
- if(x264_encoder_encode(mod->x264, &nal, &i_nal, pic_in, &pic_out) < 0) {
+ i_size = x264_encoder_encode(mod->x264, &nal, &i_nal, pic_in, &pic_out);
+
+ if(i_size<0) {
mp_msg(MSGT_MENCODER, MSGL_ERR, "x264_encoder_encode failed\n");
return -1;
}
-
- for(i=0; i < i_nal; i++) {
- int i_data = mod->mux->buffer_size - i_size;
- i_size += x264_nal_encode(mod->mux->buffer + i_size, &i_data, 1, &nal[i]);
- }
if(i_size>0) {
int keyframe = (pic_out.i_type == X264_TYPE_IDR) ||
(pic_out.i_type == X264_TYPE_I
&& param.i_frame_reference == 1
&& !param.i_bframe);
+ memcpy(mod->mux->buffer, nal->p_payload, i_size);
muxer_write_chunk(mod->mux, i_size, keyframe?0x10:0, MP_NOPTS_VALUE, MP_NOPTS_VALUE);
}
else