From: Michael Niedermayer Date: Fri, 30 Mar 2012 20:10:17 +0000 (+0200) Subject: Merge remote-tracking branch 'qatar/master' X-Git-Tag: android-x86-4.4-r1~12665 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=2b6325cacb6def8e9de0455f575b51a8bd90b12c;p=android-x86%2Fexternal-ffmpeg.git Merge remote-tracking branch 'qatar/master' * qatar/master: h264: drop ff_h264_ prefix from static function ff_h264_decode_rbsp_trailing() h264: Make ff_h264_decode_end() static, it is not used externally. output-example: K&R formatting cosmetics, comment spelling fixes avf: make the example output the proper message avf: fix audio writing in the output-example mov: don't overwrite existing indexes. lzw: fix potential integer overflow. truemotion: forbid invalid VLC bitsizes and token values. truemotion2: handle out-of-frame motion vectors through edge extension. configure: Check for a different SDL function Conflicts: configure doc/examples/muxing.c libavcodec/truemotion2.c Merged-by: Michael Niedermayer --- 2b6325cacb6def8e9de0455f575b51a8bd90b12c diff --cc configure index 6a435fd37e,4606b236e3..1eb8e923c1 --- a/configure +++ b/configure @@@ -3218,8 -2983,7 +3218,8 @@@ if enabled libdc1394; the die "ERROR: No version of libdc1394 found " fi +SDL_CONFIG="${cross_prefix}sdl-config" - if check_pkg_config sdl SDL_version.h SDL_Linked_Version; then + if check_pkg_config sdl SDL_events.h SDL_PollEvent; then check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) >= 0x010201" $sdl_cflags && enable sdl && check_struct SDL.h SDL_VideoInfo current_w $sdl_cflags && enable sdl_video_size diff --cc doc/examples/muxing.c index 5e2bf9f9b0,9dc811ca15..9d338dee67 --- a/doc/examples/muxing.c +++ b/doc/examples/muxing.c @@@ -40,10 -41,10 +40,10 @@@ #undef exit /* 5 seconds stream duration */ -#define STREAM_DURATION 5.0 +#define STREAM_DURATION 200.0 #define STREAM_FRAME_RATE 25 /* 25 images/s */ #define STREAM_NB_FRAMES ((int)(STREAM_DURATION * STREAM_FRAME_RATE)) - #define STREAM_PIX_FMT PIX_FMT_YUV420P /* default pix_fmt */ + #define STREAM_PIX_FMT PIX_FMT_YUV420P /* default pix_fmt */ static int sws_flags = SWS_BICUBIC; @@@ -200,29 -203,19 +203,29 @@@ static AVStream *add_video_stream(AVFor c = st->codec; + /* find the video encoder */ + codec = avcodec_find_encoder(codec_id); + if (!codec) { + fprintf(stderr, "codec not found\n"); + exit(1); + } + avcodec_get_context_defaults3(c, codec); + + c->codec_id = codec_id; + - /* put sample parameters */ + /* Put sample parameters. */ c->bit_rate = 400000; - /* resolution must be a multiple of two */ - c->width = 352; - c->height = 288; - /* time base: this is the fundamental unit of time (in seconds) in terms - of which frame timestamps are represented. for fixed-fps content, - timebase should be 1/framerate and timestamp increments should be - identically 1. */ + /* Resolution must be a multiple of two. */ + c->width = 352; + c->height = 288; + /* timebase: This is the fundamental unit of time (in seconds) in terms + * of which frame timestamps are represented. For fixed-fps content, + * timebase should be 1/framerate and timestamp increments should be + * identical to 1. */ c->time_base.den = STREAM_FRAME_RATE; c->time_base.num = 1; - c->gop_size = 12; /* emit one intra frame every twelve frames at most */ - c->pix_fmt = STREAM_PIX_FMT; + c->gop_size = 12; /* emit one intra frame every twelve frames at most */ + c->pix_fmt = STREAM_PIX_FMT; if (c->codec_id == CODEC_ID_MPEG2VIDEO) { /* just for testing, we also add B frames */ c->max_b_frames = 2; @@@ -384,14 -377,15 +387,16 @@@ static void write_video_frame(AVFormatC av_init_packet(&pkt); if (c->coded_frame->pts != AV_NOPTS_VALUE) - pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base, st->time_base); - if(c->coded_frame->key_frame) + pkt.pts = av_rescale_q(c->coded_frame->pts, + c->time_base, st->time_base); + if (c->coded_frame->key_frame) pkt.flags |= AV_PKT_FLAG_KEY; ++ pkt.stream_index = st->index; - pkt.data = video_outbuf; - pkt.size = out_size; + pkt.data = video_outbuf; + pkt.size = out_size; - /* write the compressed frame in the media file */ + /* Write the compressed frame to the media file. */ ret = av_interleaved_write_frame(oc, &pkt); } else { ret = 0; @@@ -442,19 -436,28 +447,19 @@@ int main(int argc, char **argv filename = argv[1]; - /* Autodetect the output format from the name. default is MPEG. */ - fmt = av_guess_format(NULL, filename, NULL); - if (!fmt) { + /* allocate the output media context */ + avformat_alloc_output_context2(&oc, NULL, NULL, filename); + if (!oc) { printf("Could not deduce output format from file extension: using MPEG.\n"); - fmt = av_guess_format("mpeg", NULL, NULL); + avformat_alloc_output_context2(&oc, NULL, "mpeg", filename); } - if (!fmt) { - fprintf(stderr, "Could not find suitable output format\n"); - return 1; - } - - /* Allocate the output media context. */ - oc = avformat_alloc_context(); if (!oc) { - fprintf(stderr, "Memory error\n"); return 1; } - oc->oformat = fmt; - snprintf(oc->filename, sizeof(oc->filename), "%s", filename); + fmt = oc->oformat; - /* add the audio and video streams using the default format codecs - and initialize the codecs */ + /* Add the audio and video streams using the default format codecs + * and initialize the codecs. */ video_st = NULL; audio_st = NULL; if (fmt->video_codec != CODEC_ID_NONE) { @@@ -481,11 -484,11 +486,12 @@@ } } - /* write the stream header, if any */ + /* Write the stream header, if any. */ avformat_write_header(oc, NULL); + + picture->pts = 0; - for(;;) { - /* compute current audio and video time */ + for (;;) { + /* Compute current audio and video time. */ if (audio_st) audio_pts = (double)audio_st->pts.val * audio_st->time_base.num / audio_st->time_base.den; else diff --cc libavcodec/h264.c index b504dcf1cb,3b1fdb2ccf..c6dc24391c --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@@ -4260,10 -4225,12 +4260,10 @@@ static int decode_nal_units(H264Contex dst_length--; bit_length = !dst_length ? 0 : (8 * dst_length - - ff_h264_decode_rbsp_trailing(h, ptr + dst_length - 1)); + decode_rbsp_trailing(h, ptr + dst_length - 1)); if (s->avctx->debug & FF_DEBUG_STARTCODE) - av_log(h->s.avctx, AV_LOG_DEBUG, - "NAL %d at %d/%d length %d\n", - hx->nal_unit_type, buf_index, buf_size, dst_length); + av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d/%d at %d/%d length %d pass %d\n", hx->nal_unit_type, hx->nal_ref_idc, buf_index, buf_size, dst_length, pass); if (h->is_avc && (nalsize != consumed) && nalsize) av_log(h->s.avctx, AV_LOG_DEBUG, diff --cc libavcodec/h264.h index 7739754948,99c46cc86a..153d83c695 --- a/libavcodec/h264.h +++ b/libavcodec/h264.h @@@ -676,9 -661,8 +676,8 @@@ int ff_h264_check_intra_pred_mode(H264C void ff_h264_hl_decode_mb(H264Context *h); int ff_h264_frame_start(H264Context *h); -int ff_h264_decode_extradata(H264Context *h); +int ff_h264_decode_extradata(H264Context *h, const uint8_t *buf, int size); av_cold int ff_h264_decode_init(AVCodecContext *avctx); - av_cold int ff_h264_decode_end(AVCodecContext *avctx); av_cold void ff_h264_decode_init_vlc(void); /** diff --cc libavcodec/truemotion2.c index 38c01c100d,67976c8337..c4f66e8f6d --- a/libavcodec/truemotion2.c +++ b/libavcodec/truemotion2.c @@@ -651,12 -651,9 +664,14 @@@ static inline void tm2_motion_block(TM2 mx = GET_TOK(ctx, TM2_MOT); my = GET_TOK(ctx, TM2_MOT); + mx = av_clip(mx, -(bx * 4 + 4), ctx->avctx->width - bx * 4); + my = av_clip(my, -(by * 4 + 4), ctx->avctx->height - by * 4); + if (4*bx+mx<0 || 4*by+my<0 || 4*bx+mx+4 > ctx->avctx->width || 4*by+my+4 > ctx->avctx->height) { + av_log(0,0, "MV out of picture\n"); + return; + } + Yo += my * oYstride + mx; Uo += (my >> 1) * oUstride + (mx >> 1); Vo += (my >> 1) * oVstride + (mx >> 1); @@@ -810,12 -844,13 +859,13 @@@ static int decode_frame(AVCodecContext for(i = 0; i < TM2_NUM_STREAMS; i++){ if (skip >= buf_size) { - av_free(swbuf); + av_log(avctx, AV_LOG_ERROR, "no space for tm2_read_stream\n"); return AVERROR_INVALIDDATA; } - t = tm2_read_stream(l, swbuf + skip, tm2_stream_order[i], buf_size - skip); ++ + t = tm2_read_stream(l, l->buffer + skip, tm2_stream_order[i], buf_size - skip); - if(t == -1){ - return -1; + if(t < 0){ - av_free(swbuf); + return t; } skip += t; } @@@ -877,15 -937,13 +952,15 @@@ static av_cold int decode_end(AVCodecCo for(i = 0; i < TM2_NUM_STREAMS; i++) av_free(l->tokens[i]); if(l->Y1){ - av_free(l->Y1); - av_free(l->U1); - av_free(l->V1); - av_free(l->Y2); - av_free(l->U2); - av_free(l->V2); + av_free(l->Y1_base); + av_free(l->U1_base); + av_free(l->V1_base); + av_free(l->Y2_base); + av_free(l->U2_base); + av_free(l->V2_base); } + av_freep(&l->buffer); + l->buffer_size = 0; if (pic->data[0]) avctx->release_buffer(avctx, pic); diff --cc libavformat/mov.c index 0e9566fe3a,1492486dcc..248620be68 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@@ -1803,15 -1727,15 +1803,16 @@@ static void mov_build_index(MOVContext unsigned int stps_index = 0; unsigned int i, j; uint64_t stream_size = 0; + AVIndexEntry *mem; /* adjust first dts according to edit list */ - if (sc->time_offset && mov->time_scale > 0) { - if (sc->time_offset < 0) - sc->time_offset = av_rescale(sc->time_offset, sc->time_scale, mov->time_scale); + if ((sc->empty_duration || sc->start_time) && mov->time_scale > 0) { + if (sc->empty_duration) + sc->empty_duration = av_rescale(sc->empty_duration, sc->time_scale, mov->time_scale); + sc->time_offset = sc->start_time - sc->empty_duration; current_dts = -sc->time_offset; - if (sc->ctts_data && sc->stts_data && sc->stts_data[0].duration && - sc->ctts_data[0].duration / sc->stts_data[0].duration > 16) { + if (sc->ctts_data && sc->stts_data && + sc->ctts_data[0].duration / FFMAX(sc->stts_data[0].duration, 1) > 16) { /* more than 16 frames delay, dts are likely wrong this happens with files created by iMovie */ sc->wrong_dts = 1; @@@ -1830,14 -1754,15 +1831,15 @@@ current_dts -= sc->dts_shift; - if (!sc->sample_count) + if (!sc->sample_count || st->nb_index_entries) return; - if (sc->sample_count >= UINT_MAX / sizeof(*st->index_entries)) + if (sc->sample_count >= UINT_MAX / sizeof(*st->index_entries) - st->nb_index_entries) return; - st->index_entries = av_malloc(sc->sample_count*sizeof(*st->index_entries)); - if (!st->index_entries) + mem = av_realloc(st->index_entries, (st->nb_index_entries + sc->sample_count) * sizeof(*st->index_entries)); + if (!mem) return; - st->index_entries_allocated_size = sc->sample_count*sizeof(*st->index_entries); + st->index_entries = mem; + st->index_entries_allocated_size = (st->nb_index_entries + sc->sample_count) * sizeof(*st->index_entries); for (i = 0; i < sc->chunk_count; i++) { current_offset = sc->chunk_offsets[i];