From 57d24225595af78b0fd836d4d145f5d181e320a2 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 8 Aug 2012 12:04:53 +0200 Subject: [PATCH 01/16] avconv: rename OutputStream.is_past_recording_time to finished. The new name is shorter and more accurate, since this variable is no longer used only for checking recording time constraint. --- avconv.c | 15 +++++++-------- avconv.h | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/avconv.c b/avconv.c index 18c2841ca2..818e05ac2a 100644 --- a/avconv.c +++ b/avconv.c @@ -345,7 +345,7 @@ static int check_recording_time(OutputStream *ost) if (of->recording_time != INT64_MAX && av_compare_ts(ost->sync_opts - ost->first_pts, ost->st->codec->time_base, of->recording_time, AV_TIME_BASE_Q) >= 0) { - ost->is_past_recording_time = 1; + ost->finished = 1; return 0; } return 1; @@ -729,8 +729,7 @@ static int poll_filters(void) for (i = 0; i < nb_output_streams; i++) { int64_t pts = output_streams[i]->sync_opts; - if (!output_streams[i]->filter || - output_streams[i]->is_past_recording_time) + if (!output_streams[i]->filter || output_streams[i]->finished) continue; pts = av_rescale_q(pts, output_streams[i]->st->codec->time_base, @@ -747,7 +746,7 @@ static int poll_filters(void) ret = poll_filter(ost); if (ret == AVERROR_EOF) { - ost->is_past_recording_time = 1; + ost->finished = 1; if (opt_shortest) return ret; @@ -983,7 +982,7 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p if (of->recording_time != INT64_MAX && ist->last_dts >= of->recording_time + of->start_time) { - ost->is_past_recording_time = 1; + ost->finished = 1; return; } @@ -1932,13 +1931,13 @@ static int need_output(void) OutputFile *of = output_files[ost->file_index]; AVFormatContext *os = output_files[ost->file_index]->ctx; - if (ost->is_past_recording_time || + if (ost->finished || (os->pb && avio_tell(os->pb) >= of->limit_filesize)) continue; if (ost->frame_number >= ost->max_frames) { int j; for (j = 0; j < of->ctx->nb_streams; j++) - output_streams[of->ost_index + j]->is_past_recording_time = 1; + output_streams[of->ost_index + j]->finished = 1; continue; } @@ -2165,7 +2164,7 @@ static int process_input(void) if (ost->source_index == ifile->ist_index + i && (ost->stream_copy || ost->enc->type == AVMEDIA_TYPE_SUBTITLE)) - ost->is_past_recording_time = 1; + ost->finished= 1; } } diff --git a/avconv.h b/avconv.h index 0cc53c5134..756d197ef5 100644 --- a/avconv.h +++ b/avconv.h @@ -288,7 +288,7 @@ typedef struct OutputStream { int64_t sws_flags; AVDictionary *opts; - int is_past_recording_time; + int finished; /* no more packets should be written for this stream */ int stream_copy; const char *attachment_filename; int copy_initial_nonkeyframes; From a5fd7c607f7aa6dad7dc2ca9b579c26ddef359d9 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 5 Aug 2012 08:30:24 +0200 Subject: [PATCH 02/16] avconv: prevent invalid reads in transcode_init() --- avconv.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/avconv.c b/avconv.c index 818e05ac2a..2566a92c14 100644 --- a/avconv.c +++ b/avconv.c @@ -1523,7 +1523,7 @@ static int transcode_init(void) { int ret = 0, i, j, k; AVFormatContext *oc; - AVCodecContext *codec, *icodec; + AVCodecContext *codec; OutputStream *ost; InputStream *ist; char error[1024]; @@ -1554,6 +1554,7 @@ static int transcode_init(void) /* for each output stream, we compute the right encoding parameters */ for (i = 0; i < nb_output_streams; i++) { + AVCodecContext *icodec = NULL; ost = output_streams[i]; oc = output_files[ost->file_index]->ctx; ist = get_input_stream(ost); @@ -1714,9 +1715,10 @@ static int transcode_init(void) ost->filter->filter->inputs[0]->sample_aspect_ratio; codec->pix_fmt = ost->filter->filter->inputs[0]->format; - if (codec->width != icodec->width || - codec->height != icodec->height || - codec->pix_fmt != icodec->pix_fmt) { + if (icodec && + (codec->width != icodec->width || + codec->height != icodec->height || + codec->pix_fmt != icodec->pix_fmt)) { codec->bits_per_raw_sample = 0; } From ab2960970171ce3c988405f99a517b9a2fd6496e Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 5 Aug 2012 08:37:43 +0200 Subject: [PATCH 03/16] avconv: allow no input files. It is now possible to use lavfi sources. --- avconv.c | 5 ----- doc/avconv.texi | 8 ++++++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/avconv.c b/avconv.c index 2566a92c14..2bc9d82378 100644 --- a/avconv.c +++ b/avconv.c @@ -2431,11 +2431,6 @@ int main(int argc, char **argv) exit_program(1); } - if (nb_input_files == 0) { - av_log(NULL, AV_LOG_FATAL, "At least one input file must be specified\n"); - exit_program(1); - } - ti = getutime(); if (transcode() < 0) exit_program(1); diff --git a/doc/avconv.texi b/doc/avconv.texi index 776a326369..ff5bb5297c 100644 --- a/doc/avconv.texi +++ b/doc/avconv.texi @@ -805,6 +805,9 @@ the matching type. Output link labels are referred to with @option{-map}. Unlabeled outputs are added to the first output file. +Note that with this option it is possible to use only lavfi sources without +normal input files. + For example, to overlay an image over video @example avconv -i video.mkv -i image.png -filter_complex '[0:v][1:v]overlay[out]' -map @@ -827,6 +830,11 @@ graph will be added to the output file automatically, so we can simply write @example avconv -i video.mkv -i image.png -filter_complex 'overlay' out.mkv @end example + +To generate 5 seconds of pure red video using lavfi @code{color} source: +@example +avconv -filter_complex 'color=red' -t 5 out.mkv +@end example @end table @c man end OPTIONS From 7ca14c731ed1fca7072c335095c2d96a6cb80fc0 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 5 Aug 2012 10:24:36 +0200 Subject: [PATCH 04/16] vsrc_movie: discourage its use with avconv. --- doc/filters.texi | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/filters.texi b/doc/filters.texi index 58a690309a..e77256e005 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -2178,6 +2178,11 @@ to the pad with identifier "in". Read a video stream from a movie container. +Note that this source is a hack that bypasses the standard input path. It can be +useful in applications that do not support arbitrary filter graphs, but its use +is discouraged in those that do. Specifically in @command{avconv} this filter +should never be used, the @option{-filter_complex} option fully replaces it. + It accepts the syntax: @var{movie_name}[:@var{options}] where @var{movie_name} is the name of the resource to read (not necessarily a file but also a device or a stream accessed through some protocol), From bfb82fcddfbebd6f9ae97165e3ccd86c5386be1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Wed, 8 Aug 2012 23:23:28 +0300 Subject: [PATCH 05/16] rtpenc: Remove an av_abort() that depends on user-supplied data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/rtpenc.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/libavformat/rtpenc.c b/libavformat/rtpenc.c index ada5a3b4f3..3f2231ffef 100644 --- a/libavformat/rtpenc.c +++ b/libavformat/rtpenc.c @@ -281,8 +281,8 @@ void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m) /* send an integer number of samples and compute time stamp and fill the rtp send buffer before sending. */ -static void rtp_send_samples(AVFormatContext *s1, - const uint8_t *buf1, int size, int sample_size_bits) +static int rtp_send_samples(AVFormatContext *s1, + const uint8_t *buf1, int size, int sample_size_bits) { RTPMuxContext *s = s1->priv_data; int len, max_packet_size, n; @@ -292,7 +292,7 @@ static void rtp_send_samples(AVFormatContext *s1, max_packet_size = (s->max_payload_size / aligned_samples_size) * aligned_samples_size; /* Not needed, but who knows. Don't check if samples aren't an even number of bytes. */ if ((sample_size_bits % 8) == 0 && ((8 * size) % sample_size_bits) != 0) - av_abort(); + return AVERROR(EINVAL); n = 0; while (size > 0) { s->buf_ptr = s->buf; @@ -307,6 +307,7 @@ static void rtp_send_samples(AVFormatContext *s1, ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0); n += (s->buf_ptr - s->buf); } + return 0; } static void rtp_send_mpegaudio(AVFormatContext *s1, @@ -461,25 +462,21 @@ static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt) case AV_CODEC_ID_PCM_ALAW: case AV_CODEC_ID_PCM_U8: case AV_CODEC_ID_PCM_S8: - rtp_send_samples(s1, pkt->data, size, 8 * st->codec->channels); - break; + return rtp_send_samples(s1, pkt->data, size, 8 * st->codec->channels); case AV_CODEC_ID_PCM_U16BE: case AV_CODEC_ID_PCM_U16LE: case AV_CODEC_ID_PCM_S16BE: case AV_CODEC_ID_PCM_S16LE: - rtp_send_samples(s1, pkt->data, size, 16 * st->codec->channels); - break; + return rtp_send_samples(s1, pkt->data, size, 16 * st->codec->channels); case AV_CODEC_ID_ADPCM_G722: /* The actual sample size is half a byte per sample, but since the * stream clock rate is 8000 Hz while the sample rate is 16000 Hz, * the correct parameter for send_samples_bits is 8 bits per stream * clock. */ - rtp_send_samples(s1, pkt->data, size, 8 * st->codec->channels); - break; + return rtp_send_samples(s1, pkt->data, size, 8 * st->codec->channels); case AV_CODEC_ID_ADPCM_G726: - rtp_send_samples(s1, pkt->data, size, - st->codec->bits_per_coded_sample * st->codec->channels); - break; + return rtp_send_samples(s1, pkt->data, size, + st->codec->bits_per_coded_sample * st->codec->channels); case AV_CODEC_ID_MP2: case AV_CODEC_ID_MP3: rtp_send_mpegaudio(s1, pkt->data, size); From c864e461d25e8ad55cefa7f320a6cf17b2666725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Wed, 8 Aug 2012 21:14:38 +0300 Subject: [PATCH 06/16] rtpdec: Remove an unused include MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/rtpdec_h264.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libavformat/rtpdec_h264.c b/libavformat/rtpdec_h264.c index acefce8bdc..d1483d497b 100644 --- a/libavformat/rtpdec_h264.c +++ b/libavformat/rtpdec_h264.c @@ -37,7 +37,6 @@ #include "libavutil/avstring.h" #include "libavcodec/get_bits.h" #include "avformat.h" -#include "mpegts.h" #include "network.h" #include From df8cf076c8627d9240e62187ac98cd88f757353c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Wed, 8 Aug 2012 21:37:47 +0300 Subject: [PATCH 07/16] rtsp: Support receiving plain data over UDP without any RTP encapsulation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit EvoStream Media Server can serve data in this format, and VLC/live555 already supports it. Signed-off-by: Martin Storsjö --- libavformat/rtsp.c | 25 +++++++++++++++++++++---- libavformat/rtsp.h | 1 + 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index d25dafacee..e03021bdb6 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -370,7 +370,9 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, get_word(buf1, sizeof(buf1), &p); /* port */ rtsp_st->sdp_port = atoi(buf1); - get_word(buf1, sizeof(buf1), &p); /* protocol (ignored) */ + get_word(buf1, sizeof(buf1), &p); /* protocol */ + if (!strcmp(buf1, "udp")) + rt->transport = RTSP_TRANSPORT_RAW; /* XXX: handle list of formats */ get_word(buf1, sizeof(buf1), &p); /* format list */ @@ -563,7 +565,7 @@ void ff_rtsp_undo_setup(AVFormatContext *s) avformat_free_context(rtpctx); } else if (rt->transport == RTSP_TRANSPORT_RDT && CONFIG_RTPDEC) ff_rdt_parse_close(rtsp_st->transport_priv); - else if (CONFIG_RTPDEC) + else if (rt->transport == RTSP_TRANSPORT_RAW && CONFIG_RTPDEC) ff_rtp_parse_close(rtsp_st->transport_priv); } rtsp_st->transport_priv = NULL; @@ -617,6 +619,8 @@ int ff_rtsp_open_transport_ctx(AVFormatContext *s, RTSPStream *rtsp_st) rtsp_st->rtp_handle = NULL; if (ret < 0) return ret; + } else if (rt->transport == RTSP_TRANSPORT_RAW) { + return 0; // Don't need to open any parser here } else if (rt->transport == RTSP_TRANSPORT_RDT && CONFIG_RTPDEC) rtsp_st->transport_priv = ff_rdt_parse_open(s, st->index, rtsp_st->dynamic_protocol_context, @@ -629,7 +633,7 @@ int ff_rtsp_open_transport_ctx(AVFormatContext *s, RTSPStream *rtsp_st) if (!rtsp_st->transport_priv) { return AVERROR(ENOMEM); - } else if (rt->transport != RTSP_TRANSPORT_RDT && CONFIG_RTPDEC) { + } else if (rt->transport == RTSP_TRANSPORT_RTP && CONFIG_RTPDEC) { if (rtsp_st->dynamic_handler) { ff_rtp_parse_set_dynamic_protocol(rtsp_st->transport_priv, rtsp_st->dynamic_protocol_context, @@ -698,6 +702,15 @@ static void rtsp_parse_transport(RTSPMessageHeader *reply, const char *p) get_word_sep(lower_transport, sizeof(lower_transport), "/;,", &p); profile[0] = '\0'; th->transport = RTSP_TRANSPORT_RDT; + } else if (!av_strcasecmp(transport_protocol, "raw")) { + get_word_sep(profile, sizeof(profile), "/;,", &p); + lower_transport[0] = '\0'; + /* raw/raw/ */ + if (*p == '/') { + get_word_sep(lower_transport, sizeof(lower_transport), + ";,", &p); + } + th->transport = RTSP_TRANSPORT_RAW; } if (!av_strcasecmp(lower_transport, "TCP")) th->lower_transport = RTSP_LOWER_TRANSPORT_TCP; @@ -1187,6 +1200,8 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, if (rt->transport == RTSP_TRANSPORT_RDT) trans_pref = "x-pn-tng"; + else if (rt->transport == RTSP_TRANSPORT_RAW) + trans_pref = "RAW/RAW"; else trans_pref = "RTP/AVP"; @@ -1822,7 +1837,7 @@ int ff_rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR_EOF; if (rt->transport == RTSP_TRANSPORT_RDT) { ret = ff_rdt_parse_packet(rtsp_st->transport_priv, pkt, &rt->recvbuf, len); - } else { + } else if (rt->transport == RTSP_TRANSPORT_RTP) { ret = ff_rtp_parse_packet(rtsp_st->transport_priv, pkt, &rt->recvbuf, len); if (ret < 0) { /* Either bad packet, or a RTCP packet. Check if the @@ -1861,6 +1876,8 @@ int ff_rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR_EOF; } } + } else { + return AVERROR_INVALIDDATA; } end: if (ret < 0) diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h index a738a3d434..704586a94e 100644 --- a/libavformat/rtsp.h +++ b/libavformat/rtsp.h @@ -52,6 +52,7 @@ enum RTSPLowerTransport { enum RTSPTransport { RTSP_TRANSPORT_RTP, /**< Standards-compliant RTP */ RTSP_TRANSPORT_RDT, /**< Realmedia Data Transport */ + RTSP_TRANSPORT_RAW, /**< Raw data (over UDP) */ RTSP_TRANSPORT_NB }; From 1243c722510f6cf878039e5edfd912ab25fe66f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Wed, 8 Aug 2012 23:05:52 +0300 Subject: [PATCH 08/16] rtsp: Support mpegts in raw udp packets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is basically the same way as mpegts packets are parsed in rtpdec.c. Signed-off-by: Martin Storsjö --- libavformat/rtsp.c | 26 +++++++++++++++++++++++++- libavformat/rtsp.h | 7 +++++++ libavformat/version.h | 2 +- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index e03021bdb6..7506d39787 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -46,6 +46,7 @@ #include "rtpenc_chain.h" #include "url.h" #include "rtpenc.h" +#include "mpegts.h" //#define DEBUG @@ -380,6 +381,8 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, if (!strcmp(ff_rtp_enc_name(rtsp_st->sdp_payload_type), "MP2T")) { /* no corresponding stream */ + if (rt->transport == RTSP_TRANSPORT_RAW && !rt->ts && CONFIG_RTPDEC) + rt->ts = ff_mpegts_parse_open(s); } else if (rt->server_type == RTSP_SERVER_WMS && codec_type == AVMEDIA_TYPE_DATA) { /* RTX stream, a stream that carries all the other actual @@ -596,6 +599,8 @@ void ff_rtsp_close_streams(AVFormatContext *s) if (rt->asf_ctx) { avformat_close_input(&rt->asf_ctx); } + if (rt->ts && CONFIG_RTPDEC) + ff_mpegts_parse_close(rt->ts); av_free(rt->p); av_free(rt->recvbuf); } @@ -1773,8 +1778,15 @@ int ff_rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt) if (rt->cur_transport_priv) { if (rt->transport == RTSP_TRANSPORT_RDT) { ret = ff_rdt_parse_packet(rt->cur_transport_priv, pkt, NULL, 0); - } else + } else if (rt->transport == RTSP_TRANSPORT_RTP) { ret = ff_rtp_parse_packet(rt->cur_transport_priv, pkt, NULL, 0); + } else if (rt->ts && CONFIG_RTPDEC) { + ret = ff_mpegts_parse_packet(rt->ts, pkt, rt->recvbuf + rt->recvbuf_pos, rt->recvbuf_len - rt->recvbuf_pos); + if (ret >= 0) { + rt->recvbuf_pos += ret; + ret = rt->recvbuf_pos < rt->recvbuf_len; + } + } if (ret == 0) { rt->cur_transport_priv = NULL; return 0; @@ -1876,6 +1888,18 @@ int ff_rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR_EOF; } } + } else if (rt->ts && CONFIG_RTPDEC) { + ret = ff_mpegts_parse_packet(rt->ts, pkt, rt->recvbuf, len); + if (ret >= 0) { + if (ret < len) { + rt->recvbuf_len = len; + rt->recvbuf_pos = ret; + rt->cur_transport_priv = rt->ts; + return 1; + } else { + ret = 0; + } + } } else { return AVERROR_INVALIDDATA; } diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h index 704586a94e..d16c98ca8a 100644 --- a/libavformat/rtsp.h +++ b/libavformat/rtsp.h @@ -311,6 +311,13 @@ typedef struct RTSPState { * other cases, this is a copy of AVFormatContext->filename. */ char control_uri[1024]; + /** The following are used for parsing raw mpegts in udp */ + //@{ + struct MpegTSContext *ts; + int recvbuf_pos; + int recvbuf_len; + //@} + /** Additional output handle, used when input and output are done * separately, eg for HTTP tunneling. */ URLContext *rtsp_hd_out; diff --git a/libavformat/version.h b/libavformat/version.h index 55026e809c..e2cd0c7f05 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -31,7 +31,7 @@ #define LIBAVFORMAT_VERSION_MAJOR 54 #define LIBAVFORMAT_VERSION_MINOR 13 -#define LIBAVFORMAT_VERSION_MICRO 1 +#define LIBAVFORMAT_VERSION_MICRO 2 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \ From f89584ca4458c84467e9fb27567e33891d1c7cd5 Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Wed, 8 Aug 2012 14:36:39 +0200 Subject: [PATCH 09/16] rtmp: Add message tracking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/rtmpproto.c | 296 +++++++++++++++++++++------------------- 1 file changed, 159 insertions(+), 137 deletions(-) diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index f6607774c2..6ad90b828f 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -52,15 +52,17 @@ typedef enum { STATE_START, ///< client has not done anything yet STATE_HANDSHAKED, ///< client has performed handshake - STATE_RELEASING, ///< client releasing stream before publish it (for output) STATE_FCPUBLISH, ///< client FCPublishing stream (for output) - STATE_CONNECTING, ///< client connected to server successfully - STATE_READY, ///< client has sent all needed commands and waits for server reply STATE_PLAYING, ///< client has started receiving multimedia data from server STATE_PUBLISHING, ///< client has started sending multimedia data to server (for output) STATE_STOPPED, ///< the broadcast has been stopped } ClientState; +typedef struct TrackedMethod { + char *name; + int id; +} TrackedMethod; + /** protocol handler context */ typedef struct RTMPContext { const AVClass *class; @@ -86,7 +88,6 @@ typedef struct RTMPContext { uint8_t flv_header[11]; ///< partial incoming flv packet header int flv_header_bytes; ///< number of initialized bytes in flv_header int nb_invokes; ///< keeps track of invoke messages - int create_stream_invoke; ///< invoke id for the create stream command char* tcurl; ///< url of the target stream char* flashver; ///< version of the flash plugin char* swfurl; ///< url of the swf player @@ -96,6 +97,9 @@ typedef struct RTMPContext { int client_buffer_time; ///< client buffer time in ms int flush_interval; ///< number of packets flushed in the same request (RTMPT only) int encrypted; ///< use an encrypted connection (RTMPE only) + TrackedMethod*tracked_methods; ///< tracked methods buffer + int nb_tracked_methods; ///< number of tracked methods + int tracked_methods_size; ///< size of the tracked methods buffer } RTMPContext; #define PLAYER_KEY_OPEN_PART_LEN 30 ///< length of partial key used for first client digest signing @@ -121,6 +125,72 @@ static const uint8_t rtmp_server_key[] = { 0xE6, 0x36, 0xCF, 0xEB, 0x31, 0xAE }; +static int add_tracked_method(RTMPContext *rt, const char *name, int id) +{ + void *ptr; + + if (rt->nb_tracked_methods + 1 > rt->tracked_methods_size) { + rt->tracked_methods_size = (rt->nb_tracked_methods + 1) * 2; + ptr = av_realloc(rt->tracked_methods, + rt->tracked_methods_size * sizeof(*rt->tracked_methods)); + if (!ptr) + return AVERROR(ENOMEM); + rt->tracked_methods = ptr; + } + + rt->tracked_methods[rt->nb_tracked_methods].name = av_strdup(name); + if (!rt->tracked_methods[rt->nb_tracked_methods].name) + return AVERROR(ENOMEM); + rt->tracked_methods[rt->nb_tracked_methods].id = id; + rt->nb_tracked_methods++; + + return 0; +} + +static void del_tracked_method(RTMPContext *rt, int index) +{ + memmove(&rt->tracked_methods[index], &rt->tracked_methods[index + 1], + sizeof(*rt->tracked_methods) * (rt->nb_tracked_methods - index - 1)); + rt->nb_tracked_methods--; +} + +static void free_tracked_methods(RTMPContext *rt) +{ + int i; + + for (i = 0; i < rt->nb_tracked_methods; i ++) + av_free(rt->tracked_methods[i].name); + av_free(rt->tracked_methods); +} + +static int rtmp_send_packet(RTMPContext *rt, RTMPPacket *pkt, int track) +{ + int ret; + + if (pkt->type == RTMP_PT_INVOKE && track) { + GetByteContext gbc; + char name[128]; + double pkt_id; + int len; + + bytestream2_init(&gbc, pkt->data, pkt->data_size); + if ((ret = ff_amf_read_string(&gbc, name, sizeof(name), &len)) < 0) + goto fail; + + if ((ret = ff_amf_read_number(&gbc, &pkt_id)) < 0) + goto fail; + + if ((ret = add_tracked_method(rt, name, pkt_id)) < 0) + goto fail; + } + + ret = ff_rtmp_packet_write(rt->stream, pkt, rt->chunk_size, + rt->prev_pkt[1]); +fail: + ff_rtmp_packet_destroy(pkt); + return ret; +} + static int rtmp_write_amf_data(URLContext *s, char *param, uint8_t **p) { char *field, *value; @@ -269,11 +339,7 @@ static int gen_connect(URLContext *s, RTMPContext *rt) pkt.data_size = p - pkt.data; - ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, - rt->prev_pkt[1]); - ff_rtmp_packet_destroy(&pkt); - - return ret; + return rtmp_send_packet(rt, &pkt, 1); } /** @@ -297,11 +363,7 @@ static int gen_release_stream(URLContext *s, RTMPContext *rt) ff_amf_write_null(&p); ff_amf_write_string(&p, rt->playpath); - ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, - rt->prev_pkt[1]); - ff_rtmp_packet_destroy(&pkt); - - return ret; + return rtmp_send_packet(rt, &pkt, 0); } /** @@ -325,11 +387,7 @@ static int gen_fcpublish_stream(URLContext *s, RTMPContext *rt) ff_amf_write_null(&p); ff_amf_write_string(&p, rt->playpath); - ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, - rt->prev_pkt[1]); - ff_rtmp_packet_destroy(&pkt); - - return ret; + return rtmp_send_packet(rt, &pkt, 0); } /** @@ -353,11 +411,7 @@ static int gen_fcunpublish_stream(URLContext *s, RTMPContext *rt) ff_amf_write_null(&p); ff_amf_write_string(&p, rt->playpath); - ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, - rt->prev_pkt[1]); - ff_rtmp_packet_destroy(&pkt); - - return ret; + return rtmp_send_packet(rt, &pkt, 0); } /** @@ -380,13 +434,8 @@ static int gen_create_stream(URLContext *s, RTMPContext *rt) ff_amf_write_string(&p, "createStream"); ff_amf_write_number(&p, ++rt->nb_invokes); ff_amf_write_null(&p); - rt->create_stream_invoke = rt->nb_invokes; - ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, - rt->prev_pkt[1]); - ff_rtmp_packet_destroy(&pkt); - - return ret; + return rtmp_send_packet(rt, &pkt, 1); } @@ -412,11 +461,7 @@ static int gen_delete_stream(URLContext *s, RTMPContext *rt) ff_amf_write_null(&p); ff_amf_write_number(&p, rt->main_channel_id); - ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, - rt->prev_pkt[1]); - ff_rtmp_packet_destroy(&pkt); - - return ret; + return rtmp_send_packet(rt, &pkt, 0); } /** @@ -437,11 +482,7 @@ static int gen_buffer_time(URLContext *s, RTMPContext *rt) bytestream_put_be32(&p, rt->main_channel_id); bytestream_put_be32(&p, rt->client_buffer_time); - ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, - rt->prev_pkt[1]); - ff_rtmp_packet_destroy(&pkt); - - return ret; + return rtmp_send_packet(rt, &pkt, 0); } /** @@ -469,11 +510,7 @@ static int gen_play(URLContext *s, RTMPContext *rt) ff_amf_write_string(&p, rt->playpath); ff_amf_write_number(&p, rt->live); - ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, - rt->prev_pkt[1]); - ff_rtmp_packet_destroy(&pkt); - - return ret; + return rtmp_send_packet(rt, &pkt, 1); } /** @@ -500,11 +537,7 @@ static int gen_publish(URLContext *s, RTMPContext *rt) ff_amf_write_string(&p, rt->playpath); ff_amf_write_string(&p, "live"); - ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, - rt->prev_pkt[1]); - ff_rtmp_packet_destroy(&pkt); - - return ret; + return rtmp_send_packet(rt, &pkt, 1); } /** @@ -529,11 +562,8 @@ static int gen_pong(URLContext *s, RTMPContext *rt, RTMPPacket *ppkt) p = pkt.data; bytestream_put_be16(&p, 7); bytestream_put_be32(&p, AV_RB32(ppkt->data+2)); - ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, - rt->prev_pkt[1]); - ff_rtmp_packet_destroy(&pkt); - return ret; + return rtmp_send_packet(rt, &pkt, 0); } /** @@ -551,11 +581,8 @@ static int gen_server_bw(URLContext *s, RTMPContext *rt) p = pkt.data; bytestream_put_be32(&p, rt->server_bw); - ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, - rt->prev_pkt[1]); - ff_rtmp_packet_destroy(&pkt); - return ret; + return rtmp_send_packet(rt, &pkt, 0); } /** @@ -576,11 +603,7 @@ static int gen_check_bw(URLContext *s, RTMPContext *rt) ff_amf_write_number(&p, RTMP_NOTIFICATION); ff_amf_write_null(&p); - ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, - rt->prev_pkt[1]); - ff_rtmp_packet_destroy(&pkt); - - return ret; + return rtmp_send_packet(rt, &pkt, 0); } /** @@ -598,11 +621,8 @@ static int gen_bytes_read(URLContext *s, RTMPContext *rt, uint32_t ts) p = pkt.data; bytestream_put_be32(&p, rt->bytes_read); - ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, - rt->prev_pkt[1]); - ff_rtmp_packet_destroy(&pkt); - return ret; + return rtmp_send_packet(rt, &pkt, 0); } static int gen_fcsubscribe_stream(URLContext *s, RTMPContext *rt, @@ -622,11 +642,7 @@ static int gen_fcsubscribe_stream(URLContext *s, RTMPContext *rt, ff_amf_write_null(&p); ff_amf_write_string(&p, subscribe); - ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, - rt->prev_pkt[1]); - ff_rtmp_packet_destroy(&pkt); - - return ret; + return rtmp_send_packet(rt, &pkt, 1); } int ff_rtmp_calc_digest(const uint8_t *src, int len, int gap, @@ -1010,7 +1026,8 @@ static int handle_invoke(URLContext *s, RTMPPacket *pkt) RTMPContext *rt = s->priv_data; int i, t; const uint8_t *data_end = pkt->data + pkt->data_size; - int ret; + char *tracked_method = NULL; + int ret = 0; //TODO: check for the messages sent for wrong state? if (!memcmp(pkt->data, "\002\000\006_error", 9)) { @@ -1021,68 +1038,72 @@ static int handle_invoke(URLContext *s, RTMPPacket *pkt) av_log(s, AV_LOG_ERROR, "Server error: %s\n",tmpstr); return -1; } else if (!memcmp(pkt->data, "\002\000\007_result", 10)) { - switch (rt->state) { - case STATE_HANDSHAKED: - if (!rt->is_input) { - if ((ret = gen_release_stream(s, rt)) < 0) - return ret; - if ((ret = gen_fcpublish_stream(s, rt)) < 0) - return ret; - rt->state = STATE_RELEASING; - } else { - if ((ret = gen_server_bw(s, rt)) < 0) - return ret; - rt->state = STATE_CONNECTING; - } - if ((ret = gen_create_stream(s, rt)) < 0) - return ret; + GetByteContext gbc; + double pkt_id; - if (rt->is_input) { - /* Send the FCSubscribe command when the name of live - * stream is defined by the user or if it's a live stream. */ - if (rt->subscribe) { - if ((ret = gen_fcsubscribe_stream(s, rt, - rt->subscribe)) < 0) - return ret; - } else if (rt->live == -1) { - if ((ret = gen_fcsubscribe_stream(s, rt, - rt->playpath)) < 0) - return ret; - } + bytestream2_init(&gbc, pkt->data + 10, pkt->data_size); + if ((ret = ff_amf_read_number(&gbc, &pkt_id)) < 0) + return ret; + + for (i = 0; i < rt->nb_tracked_methods; i++) { + if (rt->tracked_methods[i].id != pkt_id) + continue; + + tracked_method = rt->tracked_methods[i].name; + del_tracked_method(rt, i); + break; + } + + if (!tracked_method) { + /* Ignore this reply when the current method is not tracked. */ + return 0; + } + + if (!memcmp(tracked_method, "connect", 7)) { + if (!rt->is_input) { + if ((ret = gen_release_stream(s, rt)) < 0) + goto invoke_fail; + + if ((ret = gen_fcpublish_stream(s, rt)) < 0) + goto invoke_fail; + } else { + if ((ret = gen_server_bw(s, rt)) < 0) + goto invoke_fail; + } + + if ((ret = gen_create_stream(s, rt)) < 0) + goto invoke_fail; + + if (rt->is_input) { + /* Send the FCSubscribe command when the name of live + * stream is defined by the user or if it's a live stream. */ + if (rt->subscribe) { + if ((ret = gen_fcsubscribe_stream(s, rt, + rt->subscribe)) < 0) + goto invoke_fail; + } else if (rt->live == -1) { + if ((ret = gen_fcsubscribe_stream(s, rt, + rt->playpath)) < 0) + goto invoke_fail; } - break; - case STATE_FCPUBLISH: - rt->state = STATE_CONNECTING; - break; - case STATE_RELEASING: - rt->state = STATE_FCPUBLISH; - /* hack for Wowza Media Server, it does not send result for - * releaseStream and FCPublish calls */ - if (!pkt->data[10]) { - int pkt_id = av_int2double(AV_RB64(pkt->data + 11)); - if (pkt_id == rt->create_stream_invoke) - rt->state = STATE_CONNECTING; - } - if (rt->state != STATE_CONNECTING) - break; - case STATE_CONNECTING: - //extract a number from the result - if (pkt->data[10] || pkt->data[19] != 5 || pkt->data[20]) { - av_log(s, AV_LOG_WARNING, "Unexpected reply on connect()\n"); - } else { - rt->main_channel_id = av_int2double(AV_RB64(pkt->data + 21)); - } - if (rt->is_input) { - if ((ret = gen_play(s, rt)) < 0) - return ret; - if ((ret = gen_buffer_time(s, rt)) < 0) - return ret; - } else { - if ((ret = gen_publish(s, rt)) < 0) - return ret; - } - rt->state = STATE_READY; - break; + } + } else if (!memcmp(tracked_method, "createStream", 12)) { + //extract a number from the result + if (pkt->data[10] || pkt->data[19] != 5 || pkt->data[20]) { + av_log(s, AV_LOG_WARNING, "Unexpected reply on connect()\n"); + } else { + rt->main_channel_id = av_int2double(AV_RB64(pkt->data + 21)); + } + + if (!rt->is_input) { + if ((ret = gen_publish(s, rt)) < 0) + goto invoke_fail; + } else { + if ((ret = gen_play(s, rt)) < 0) + goto invoke_fail; + if ((ret = gen_buffer_time(s, rt)) < 0) + goto invoke_fail; + } } } else if (!memcmp(pkt->data, "\002\000\010onStatus", 11)) { const uint8_t* ptr = pkt->data + 11; @@ -1113,7 +1134,9 @@ static int handle_invoke(URLContext *s, RTMPPacket *pkt) return ret; } - return 0; +invoke_fail: + av_free(tracked_method); + return ret; } /** @@ -1283,6 +1306,7 @@ static int rtmp_close(URLContext *h) if (rt->state > STATE_HANDSHAKED) ret = gen_delete_stream(h, rt); + free_tracked_methods(rt); av_freep(&rt->flv_data); ffurl_close(rt->stream); return ret; @@ -1570,10 +1594,8 @@ static int rtmp_write(URLContext *s, const uint8_t *buf, int size) if (rt->flv_off == rt->flv_size) { rt->skip_bytes = 4; - if ((ret = ff_rtmp_packet_write(rt->stream, &rt->out_pkt, - rt->chunk_size, rt->prev_pkt[1])) < 0) + if ((ret = rtmp_send_packet(rt, &rt->out_pkt, 0)) < 0) return ret; - ff_rtmp_packet_destroy(&rt->out_pkt); rt->flv_size = 0; rt->flv_off = 0; rt->flv_header_bytes = 0; From 122d5c526a43122b1f9ac9bce79e3938c8354e43 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Tue, 7 Aug 2012 12:19:58 -0700 Subject: [PATCH 10/16] aacdec: Don't fall back to the old output configuration when no old configuration is present. Fixes MP4 files where the first frame is broken. --- libavcodec/aacdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c index 958c9d2f97..1c59ec5937 100644 --- a/libavcodec/aacdec.c +++ b/libavcodec/aacdec.c @@ -365,7 +365,7 @@ static void push_output_configuration(AACContext *ac) { * configuration is unlocked. */ static void pop_output_configuration(AACContext *ac) { - if (ac->oc[1].status != OC_LOCKED) { + if (ac->oc[1].status != OC_LOCKED && ac->oc[0].status != OC_NONE) { ac->oc[1] = ac->oc[0]; ac->avctx->channels = ac->oc[1].channels; ac->avctx->channel_layout = ac->oc[1].channel_layout; From c318626ce248e55df032146b16e8e0f4ed1d99fb Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Wed, 8 Aug 2012 13:51:52 +0100 Subject: [PATCH 11/16] x86: rename libavutil/x86_cpu.h to libavutil/x86/asm.h This puts x86-specific things in the x86/ subdirectory where they belong. Signed-off-by: Mans Rullgard --- libavcodec/msmpeg4.c | 2 +- libavcodec/x86/ac3dsp_mmx.c | 2 +- libavcodec/x86/cabac.h | 2 +- libavcodec/x86/cavsdsp_mmx.c | 2 +- libavcodec/x86/dnxhd_mmx.c | 2 +- libavcodec/x86/dsputil_mmx.c | 2 +- libavcodec/x86/dsputil_mmx.h | 2 +- libavcodec/x86/dsputilenc_mmx.c | 2 +- libavcodec/x86/fdct_mmx.c | 2 +- libavcodec/x86/fmtconvert_mmx.c | 2 +- libavcodec/x86/h264dsp_mmx.c | 2 +- libavcodec/x86/idct_sse2_xvid.c | 2 +- libavcodec/x86/lpc_mmx.c | 2 +- libavcodec/x86/mlpdsp.c | 2 +- libavcodec/x86/motion_est_mmx.c | 2 +- libavcodec/x86/mpegaudiodec_mmx.c | 2 +- libavcodec/x86/mpegvideo_mmx.c | 2 +- libavcodec/x86/rv34dsp_init.c | 2 +- libavcodec/x86/snowdsp_mmx.c | 2 +- libavcodec/x86/vc1dsp_mmx.c | 2 +- libavcodec/x86/vp56dsp_init.c | 2 +- libavcodec/x86/vp8dsp-init.c | 2 +- libavfilter/x86/gradfun.c | 2 +- libavfilter/x86/yadif.c | 2 +- libavutil/{x86_cpu.h => x86/asm.h} | 6 +++--- libavutil/x86/cpu.c | 2 +- libswscale/utils.c | 2 +- libswscale/x86/rgb2rgb.c | 2 +- libswscale/x86/swscale.c | 2 +- libswscale/x86/yuv2rgb.c | 2 +- 30 files changed, 32 insertions(+), 32 deletions(-) rename libavutil/{x86_cpu.h => x86/asm.h} (97%) diff --git a/libavcodec/msmpeg4.c b/libavcodec/msmpeg4.c index e20f9b251a..c4ef22e74c 100644 --- a/libavcodec/msmpeg4.c +++ b/libavcodec/msmpeg4.c @@ -31,7 +31,7 @@ #include "dsputil.h" #include "mpegvideo.h" #include "msmpeg4.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "h263.h" #include "mpeg4video.h" #include "msmpeg4data.h" diff --git a/libavcodec/x86/ac3dsp_mmx.c b/libavcodec/x86/ac3dsp_mmx.c index 0ac8685c6d..f3db67a84f 100644 --- a/libavcodec/x86/ac3dsp_mmx.c +++ b/libavcodec/x86/ac3dsp_mmx.c @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "dsputil_mmx.h" #include "libavcodec/ac3dsp.h" diff --git a/libavcodec/x86/cabac.h b/libavcodec/x86/cabac.h index 02dbc54db7..389f155745 100644 --- a/libavcodec/x86/cabac.h +++ b/libavcodec/x86/cabac.h @@ -23,7 +23,7 @@ #include "libavcodec/cabac.h" #include "libavutil/attributes.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavutil/internal.h" #include "config.h" diff --git a/libavcodec/x86/cavsdsp_mmx.c b/libavcodec/x86/cavsdsp_mmx.c index 4ed7d8e598..e94003956f 100644 --- a/libavcodec/x86/cavsdsp_mmx.c +++ b/libavcodec/x86/cavsdsp_mmx.c @@ -24,7 +24,7 @@ #include "libavutil/common.h" #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/dsputil.h" #include "libavcodec/cavsdsp.h" #include "dsputil_mmx.h" diff --git a/libavcodec/x86/dnxhd_mmx.c b/libavcodec/x86/dnxhd_mmx.c index 54293aa280..12fe3ae55f 100644 --- a/libavcodec/x86/dnxhd_mmx.c +++ b/libavcodec/x86/dnxhd_mmx.c @@ -21,7 +21,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/dnxhdenc.h" #if HAVE_INLINE_ASM diff --git a/libavcodec/x86/dsputil_mmx.c b/libavcodec/x86/dsputil_mmx.c index f13e920bed..93f9db8299 100644 --- a/libavcodec/x86/dsputil_mmx.c +++ b/libavcodec/x86/dsputil_mmx.c @@ -23,7 +23,7 @@ */ #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/dsputil.h" #include "libavcodec/h264dsp.h" #include "libavcodec/mpegvideo.h" diff --git a/libavcodec/x86/dsputil_mmx.h b/libavcodec/x86/dsputil_mmx.h index f1db78d5c4..316c384d1a 100644 --- a/libavcodec/x86/dsputil_mmx.h +++ b/libavcodec/x86/dsputil_mmx.h @@ -24,7 +24,7 @@ #include #include "libavcodec/dsputil.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" typedef struct { uint64_t a, b; } xmm_reg; diff --git a/libavcodec/x86/dsputilenc_mmx.c b/libavcodec/x86/dsputilenc_mmx.c index 0ac4d2c10d..c0ef0bac3e 100644 --- a/libavcodec/x86/dsputilenc_mmx.c +++ b/libavcodec/x86/dsputilenc_mmx.c @@ -23,7 +23,7 @@ */ #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/dsputil.h" #include "libavcodec/mpegvideo.h" #include "libavcodec/mathops.h" diff --git a/libavcodec/x86/fdct_mmx.c b/libavcodec/x86/fdct_mmx.c index 3614fd151a..f9bd3f2508 100644 --- a/libavcodec/x86/fdct_mmx.c +++ b/libavcodec/x86/fdct_mmx.c @@ -31,7 +31,7 @@ */ #include "libavutil/common.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/dsputil.h" #if HAVE_INLINE_ASM diff --git a/libavcodec/x86/fmtconvert_mmx.c b/libavcodec/x86/fmtconvert_mmx.c index fbdc5262b9..6f3d14aedc 100644 --- a/libavcodec/x86/fmtconvert_mmx.c +++ b/libavcodec/x86/fmtconvert_mmx.c @@ -23,7 +23,7 @@ */ #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/fmtconvert.h" #include "libavcodec/dsputil.h" diff --git a/libavcodec/x86/h264dsp_mmx.c b/libavcodec/x86/h264dsp_mmx.c index 0612ffbb8b..f24f751fb3 100644 --- a/libavcodec/x86/h264dsp_mmx.c +++ b/libavcodec/x86/h264dsp_mmx.c @@ -19,7 +19,7 @@ */ #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/h264dsp.h" #include "dsputil_mmx.h" diff --git a/libavcodec/x86/idct_sse2_xvid.c b/libavcodec/x86/idct_sse2_xvid.c index 8249e97ccf..b58db79a5a 100644 --- a/libavcodec/x86/idct_sse2_xvid.c +++ b/libavcodec/x86/idct_sse2_xvid.c @@ -39,7 +39,7 @@ */ #include "libavcodec/dsputil.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "idct_xvid.h" #include "dsputil_mmx.h" diff --git a/libavcodec/x86/lpc_mmx.c b/libavcodec/x86/lpc_mmx.c index 27bebe856a..609f4e5cd2 100644 --- a/libavcodec/x86/lpc_mmx.c +++ b/libavcodec/x86/lpc_mmx.c @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavutil/cpu.h" #include "libavcodec/lpc.h" diff --git a/libavcodec/x86/mlpdsp.c b/libavcodec/x86/mlpdsp.c index 400855d7c4..16e38c3313 100644 --- a/libavcodec/x86/mlpdsp.c +++ b/libavcodec/x86/mlpdsp.c @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/dsputil.h" #include "libavcodec/mlp.h" diff --git a/libavcodec/x86/motion_est_mmx.c b/libavcodec/x86/motion_est_mmx.c index 68b1633a47..c3136eb1fe 100644 --- a/libavcodec/x86/motion_est_mmx.c +++ b/libavcodec/x86/motion_est_mmx.c @@ -22,7 +22,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/dsputil.h" #include "dsputil_mmx.h" diff --git a/libavcodec/x86/mpegaudiodec_mmx.c b/libavcodec/x86/mpegaudiodec_mmx.c index 88a347796c..701ae75138 100644 --- a/libavcodec/x86/mpegaudiodec_mmx.c +++ b/libavcodec/x86/mpegaudiodec_mmx.c @@ -20,7 +20,7 @@ */ #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/dsputil.h" #include "libavcodec/mpegaudiodsp.h" diff --git a/libavcodec/x86/mpegvideo_mmx.c b/libavcodec/x86/mpegvideo_mmx.c index 85f6866342..46ed30a76d 100644 --- a/libavcodec/x86/mpegvideo_mmx.c +++ b/libavcodec/x86/mpegvideo_mmx.c @@ -23,7 +23,7 @@ */ #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/avcodec.h" #include "libavcodec/dsputil.h" #include "libavcodec/mpegvideo.h" diff --git a/libavcodec/x86/rv34dsp_init.c b/libavcodec/x86/rv34dsp_init.c index 7284a9beaf..b07ad89f0e 100644 --- a/libavcodec/x86/rv34dsp_init.c +++ b/libavcodec/x86/rv34dsp_init.c @@ -20,7 +20,7 @@ */ #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/dsputil.h" #include "libavcodec/rv34dsp.h" diff --git a/libavcodec/x86/snowdsp_mmx.c b/libavcodec/x86/snowdsp_mmx.c index 770cc1cc73..fb190d8d8d 100644 --- a/libavcodec/x86/snowdsp_mmx.c +++ b/libavcodec/x86/snowdsp_mmx.c @@ -20,7 +20,7 @@ */ #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/avcodec.h" #include "libavcodec/snow.h" #include "libavcodec/dwt.h" diff --git a/libavcodec/x86/vc1dsp_mmx.c b/libavcodec/x86/vc1dsp_mmx.c index aae08c2364..9200798310 100644 --- a/libavcodec/x86/vc1dsp_mmx.c +++ b/libavcodec/x86/vc1dsp_mmx.c @@ -25,7 +25,7 @@ */ #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/dsputil.h" #include "dsputil_mmx.h" #include "libavcodec/vc1dsp.h" diff --git a/libavcodec/x86/vp56dsp_init.c b/libavcodec/x86/vp56dsp_init.c index 69c197e520..aa5f5e5d4f 100644 --- a/libavcodec/x86/vp56dsp_init.c +++ b/libavcodec/x86/vp56dsp_init.c @@ -21,7 +21,7 @@ */ #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/dsputil.h" #include "libavcodec/vp56dsp.h" diff --git a/libavcodec/x86/vp8dsp-init.c b/libavcodec/x86/vp8dsp-init.c index 64dd8ceadf..4568a3864c 100644 --- a/libavcodec/x86/vp8dsp-init.c +++ b/libavcodec/x86/vp8dsp-init.c @@ -21,7 +21,7 @@ */ #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/vp8dsp.h" #if HAVE_YASM diff --git a/libavfilter/x86/gradfun.c b/libavfilter/x86/gradfun.c index b45256d011..4cd481c05f 100644 --- a/libavfilter/x86/gradfun.c +++ b/libavfilter/x86/gradfun.c @@ -20,7 +20,7 @@ #include "libavutil/attributes.h" #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavfilter/gradfun.h" #if HAVE_INLINE_ASM diff --git a/libavfilter/x86/yadif.c b/libavfilter/x86/yadif.c index 81b536acda..ee3a016bd0 100644 --- a/libavfilter/x86/yadif.c +++ b/libavfilter/x86/yadif.c @@ -20,7 +20,7 @@ #include "libavutil/attributes.h" #include "libavutil/cpu.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavcodec/x86/dsputil_mmx.h" #include "libavfilter/yadif.h" diff --git a/libavutil/x86_cpu.h b/libavutil/x86/asm.h similarity index 97% rename from libavutil/x86_cpu.h rename to libavutil/x86/asm.h index f84eba67f5..b447fabb57 100644 --- a/libavutil/x86_cpu.h +++ b/libavutil/x86/asm.h @@ -18,8 +18,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AVUTIL_X86_CPU_H -#define AVUTIL_X86_CPU_H +#ifndef AVUTIL_X86_ASM_H +#define AVUTIL_X86_ASM_H #include #include "config.h" @@ -95,4 +95,4 @@ typedef int x86_reg; # define XMM_CLOBBERS_ONLY(...) #endif -#endif /* AVUTIL_X86_CPU_H */ +#endif /* AVUTIL_X86_ASM_H */ diff --git a/libavutil/x86/cpu.c b/libavutil/x86/cpu.c index a63b564985..645bb83f77 100644 --- a/libavutil/x86/cpu.c +++ b/libavutil/x86/cpu.c @@ -22,7 +22,7 @@ #include #include -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavutil/cpu.h" #if HAVE_INLINE_ASM diff --git a/libswscale/utils.c b/libswscale/utils.c index 9a57405d2c..f890b5cee1 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -45,7 +45,7 @@ #include "libavutil/mathematics.h" #include "libavutil/opt.h" #include "libavutil/pixdesc.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "rgb2rgb.h" #include "swscale.h" #include "swscale_internal.h" diff --git a/libswscale/x86/rgb2rgb.c b/libswscale/x86/rgb2rgb.c index 066749c22f..f201281fac 100644 --- a/libswscale/x86/rgb2rgb.c +++ b/libswscale/x86/rgb2rgb.c @@ -27,7 +27,7 @@ #include "config.h" #include "libavutil/attributes.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavutil/cpu.h" #include "libavutil/bswap.h" #include "libswscale/rgb2rgb.h" diff --git a/libswscale/x86/swscale.c b/libswscale/x86/swscale.c index 57d270b09d..9683c0cedd 100644 --- a/libswscale/x86/swscale.c +++ b/libswscale/x86/swscale.c @@ -24,7 +24,7 @@ #include "libswscale/swscale_internal.h" #include "libavutil/attributes.h" #include "libavutil/intreadwrite.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavutil/cpu.h" #include "libavutil/pixdesc.h" diff --git a/libswscale/x86/yuv2rgb.c b/libswscale/x86/yuv2rgb.c index 501993ae42..93755493ab 100644 --- a/libswscale/x86/yuv2rgb.c +++ b/libswscale/x86/yuv2rgb.c @@ -34,7 +34,7 @@ #include "libswscale/swscale.h" #include "libswscale/swscale_internal.h" #include "libavutil/attributes.h" -#include "libavutil/x86_cpu.h" +#include "libavutil/x86/asm.h" #include "libavutil/cpu.h" #if HAVE_INLINE_ASM From 070a402b60cb4ebc6fd2ba59c13758811815bb19 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Wed, 8 Aug 2012 14:37:57 +0100 Subject: [PATCH 12/16] x86: move MANGLE() and related macros to libavutil/x86/asm.h These x86-specific macros do not belong in generic code. Signed-off-by: Mans Rullgard --- libavutil/internal.h | 12 ------------ libavutil/x86/asm.h | 12 ++++++++++++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/libavutil/internal.h b/libavutil/internal.h index e8bcca571b..0a7ed83c4f 100644 --- a/libavutil/internal.h +++ b/libavutil/internal.h @@ -92,18 +92,6 @@ struct AVDictionary { # define offsetof(T, F) ((unsigned int)((char *)&((T *)0)->F)) #endif -/* Use to export labels from asm. */ -#define LABEL_MANGLE(a) EXTERN_PREFIX #a - -// Use rip-relative addressing if compiling PIC code on x86-64. -#if ARCH_X86_64 && defined(PIC) -# define LOCAL_MANGLE(a) #a "(%%rip)" -#else -# define LOCAL_MANGLE(a) #a -#endif - -#define MANGLE(a) EXTERN_PREFIX LOCAL_MANGLE(a) - /* debug stuff */ #define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0) diff --git a/libavutil/x86/asm.h b/libavutil/x86/asm.h index b447fabb57..a43ab3c074 100644 --- a/libavutil/x86/asm.h +++ b/libavutil/x86/asm.h @@ -95,4 +95,16 @@ typedef int x86_reg; # define XMM_CLOBBERS_ONLY(...) #endif +/* Use to export labels from asm. */ +#define LABEL_MANGLE(a) EXTERN_PREFIX #a + +// Use rip-relative addressing if compiling PIC code on x86-64. +#if ARCH_X86_64 && defined(PIC) +# define LOCAL_MANGLE(a) #a "(%%rip)" +#else +# define LOCAL_MANGLE(a) #a +#endif + +#define MANGLE(a) EXTERN_PREFIX LOCAL_MANGLE(a) + #endif /* AVUTIL_X86_ASM_H */ From d7a4f8f8b9a4bc309d4d5ab067cfba945e690c0c Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Wed, 8 Aug 2012 17:13:26 +0100 Subject: [PATCH 13/16] Move MASK_ABS macro to libavcodec/mathops.h This macro is only used in two places, both in libavcodec, so this is a more sensible place for it. Two small tweaks to the macro are made: - removing the trailing semicolon - dropping unnecessary 'volatile' from the x86 asm Signed-off-by: Mans Rullgard --- libavcodec/mathops.h | 7 +++++++ libavcodec/mpeg12enc.c | 2 +- libavcodec/x86/mathops.h | 6 ++++++ libavutil/internal.h | 16 ---------------- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/libavcodec/mathops.h b/libavcodec/mathops.h index d6eb98ddac..ab545ef504 100644 --- a/libavcodec/mathops.h +++ b/libavcodec/mathops.h @@ -138,6 +138,13 @@ if ((y) < (x)) {\ } #endif +#ifndef MASK_ABS +#define MASK_ABS(mask, level) do { \ + mask = level >> 31; \ + level = (level ^ mask) - mask; \ + } while (0) +#endif + #ifndef NEG_SSR32 # define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s))) #endif diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c index cb3e9d5a70..a96a23dd6b 100644 --- a/libavcodec/mpeg12enc.c +++ b/libavcodec/mpeg12enc.c @@ -885,7 +885,7 @@ static void mpeg1_encode_block(MpegEncContext *s, run = i - last_non_zero - 1; alevel= level; - MASK_ABS(sign, alevel) + MASK_ABS(sign, alevel); sign&=1; if (alevel <= mpeg1_max_level[0][run]){ diff --git a/libavcodec/x86/mathops.h b/libavcodec/x86/mathops.h index e056eb0a2d..cd408ac5a6 100644 --- a/libavcodec/x86/mathops.h +++ b/libavcodec/x86/mathops.h @@ -101,6 +101,12 @@ __asm__ volatile(\ ); #endif +#define MASK_ABS(mask, level) \ + __asm__ ("cltd \n\t" \ + "xorl %1, %0 \n\t" \ + "subl %1, %0 \n\t" \ + : "+a"(level), "=&d"(mask)) + // avoid +32 for shift optimization (gcc should do that ...) #define NEG_SSR32 NEG_SSR32 static inline int32_t NEG_SSR32( int32_t a, int8_t s){ diff --git a/libavutil/internal.h b/libavutil/internal.h index 0a7ed83c4f..4c1d2f6648 100644 --- a/libavutil/internal.h +++ b/libavutil/internal.h @@ -96,22 +96,6 @@ struct AVDictionary { #define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0) -/* math */ - -#if ARCH_X86 && HAVE_INLINE_ASM -#define MASK_ABS(mask, level)\ - __asm__ volatile(\ - "cltd \n\t"\ - "xorl %1, %0 \n\t"\ - "subl %1, %0 \n\t"\ - : "+a" (level), "=&d" (mask)\ - ); -#else -#define MASK_ABS(mask, level)\ - mask = level >> 31;\ - level = (level ^ mask) - mask; -#endif - /* avoid usage of dangerous/inappropriate system functions */ #undef malloc #define malloc please_use_av_malloc From 18bbca1fd31360b6d21710db70d321fa0333e7a5 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Sat, 4 Aug 2012 00:05:46 +0100 Subject: [PATCH 14/16] build: factor out mpegvideo.o dependencies to CONFIG_MPEGVIDEO This adds a hidden config variable for the mpegvideo.o dependency and selects from the codecs which require it. Signed-off-by: Mans Rullgard --- configure | 46 +++++++++++++++++++------------- libavcodec/Makefile | 65 ++++++++++++++++++++------------------------- 2 files changed, 57 insertions(+), 54 deletions(-) diff --git a/configure b/configure index 9bdeebde45..241663c07d 100755 --- a/configure +++ b/configure @@ -1226,6 +1226,7 @@ CONFIG_EXTRA=" lgplv3 lpc mpegaudiodsp + mpegvideo nettle rtpdec sinewin @@ -1349,17 +1350,17 @@ atrac1_decoder_select="mdct sinewin" atrac3_decoder_select="mdct" binkaudio_dct_decoder_select="mdct rdft dct sinewin" binkaudio_rdft_decoder_select="mdct rdft sinewin" -cavs_decoder_select="golomb" +cavs_decoder_select="golomb mpegvideo" cook_decoder_select="mdct sinewin" cscd_decoder_suggest="zlib" dca_decoder_select="mdct" -dnxhd_encoder_select="aandcttables" +dnxhd_encoder_select="aandcttables mpegvideo" dxa_decoder_select="zlib" eac3_decoder_select="ac3_decoder" eac3_encoder_select="mdct ac3dsp" eamad_decoder_select="aandcttables" eatgq_decoder_select="aandcttables" -eatqi_decoder_select="aandcttables" +eatqi_decoder_select="aandcttables mpegvideo" ffv1_decoder_select="golomb" flac_decoder_select="golomb" flac_encoder_select="golomb lpc" @@ -1369,13 +1370,14 @@ flashsv2_decoder_select="zlib" flv_decoder_select="h263_decoder" flv_encoder_select="h263_encoder" fraps_decoder_select="huffman" -h261_encoder_select="aandcttables" -h263_decoder_select="h263_parser" -h263_encoder_select="aandcttables" +h261_decoder_select="mpegvideo" +h261_encoder_select="aandcttables mpegvideo" +h263_decoder_select="h263_parser mpegvideo" +h263_encoder_select="aandcttables mpegvideo" h263_vaapi_hwaccel_select="vaapi h263_decoder" h263i_decoder_select="h263_decoder" h263p_encoder_select="h263_encoder" -h264_decoder_select="golomb h264chroma h264dsp h264pred h264qpel" +h264_decoder_select="golomb h264chroma h264dsp h264pred h264qpel mpegvideo" h264_dxva2_hwaccel_deps="dxva2api_h" h264_dxva2_hwaccel_select="dxva2 h264_decoder" h264_vaapi_hwaccel_select="vaapi h264_decoder" @@ -1385,9 +1387,10 @@ iac_decoder_select="fft mdct sinewin" imc_decoder_select="fft mdct sinewin" jpegls_decoder_select="golomb" jpegls_encoder_select="golomb" -ljpeg_encoder_select="aandcttables" +ljpeg_encoder_select="aandcttables mpegvideo" loco_decoder_select="golomb" -mjpeg_encoder_select="aandcttables" +mdec_decoder_select="mpegvideo" +mjpeg_encoder_select="aandcttables mpegvideo" mlp_decoder_select="mlp_parser" mp1_decoder_select="mpegaudiodsp" mp1float_decoder_select="mpegaudiodsp" @@ -1405,11 +1408,13 @@ mpeg_vdpau_decoder_select="vdpau mpegvideo_decoder" mpeg_xvmc_decoder_deps="X11_extensions_XvMClib_h" mpeg_xvmc_decoder_select="mpegvideo_decoder" mpeg1_vdpau_decoder_select="vdpau mpeg1video_decoder" -mpeg1video_encoder_select="aandcttables" +mpeg1video_decoder_select="mpegvideo" +mpeg1video_encoder_select="aandcttables mpegvideo" mpeg2_dxva2_hwaccel_deps="dxva2api_h" mpeg2_dxva2_hwaccel_select="dxva2 mpeg2video_decoder" mpeg2_vaapi_hwaccel_select="vaapi mpeg2video_decoder" -mpeg2video_encoder_select="aandcttables" +mpeg2video_encoder_select="mpegvideo" +mpeg2video_encoder_select="aandcttables mpegvideo" mpeg4_decoder_select="h263_decoder mpeg4video_parser" mpeg4_encoder_select="h263_encoder" mpeg4_vaapi_hwaccel_select="vaapi mpeg4_decoder" @@ -1432,14 +1437,15 @@ rv10_decoder_select="h263_decoder" rv10_encoder_select="h263_encoder" rv20_decoder_select="h263_decoder" rv20_encoder_select="h263_encoder" -rv30_decoder_select="golomb h264chroma h264pred h264qpel" -rv40_decoder_select="golomb h264chroma h264pred h264qpel" +rv30_decoder_select="golomb h264chroma h264pred h264qpel mpegvideo" +rv40_decoder_select="golomb h264chroma h264pred h264qpel mpegvideo" shorten_decoder_select="golomb" sipr_decoder_select="lsp" snow_decoder_select="dwt" -snow_encoder_select="aandcttables dwt" -svq1_encoder_select="aandcttables" -svq3_decoder_select="golomb h264chroma h264dsp h264pred h264qpel" +snow_encoder_select="aandcttables dwt mpegvideo" +svq1_encoder_select="mpegvideo" +svq1_encoder_select="aandcttables mpegvideo" +svq3_decoder_select="golomb h264chroma h264dsp h264pred h264qpel mpegvideo" svq3_decoder_suggest="zlib" theora_decoder_select="vp3_decoder" tiff_decoder_suggest="zlib" @@ -1487,7 +1493,10 @@ vda_deps="VideoDecodeAcceleration_VDADecoder_h pthreads" vdpau_deps="vdpau_vdpau_h vdpau_vdpau_x11_h" # parsers -h264_parser_select="golomb h264dsp h264pred" +h264_parser_select="golomb h264dsp h264pred mpegvideo" +mpeg4video_parser_select="mpegvideo" +mpegvideo_parser_select="mpegvideo" +vc1_parser_select="mpegvideo" # external libraries libfaac_encoder_deps="libfaac" @@ -1531,12 +1540,13 @@ matroska_demuxer_suggest="zlib bzlib" mov_demuxer_suggest="zlib" mp3_demuxer_select="mpegaudio_parser" mp4_muxer_select="mov_muxer" -mpegts_muxer_select="adts_muxer latm_muxer" +mpegts_muxer_select="adts_muxer latm_muxer mpegvideo" mpegtsraw_demuxer_select="mpegts_demuxer" mxf_d10_muxer_select="mxf_muxer" ogg_demuxer_select="golomb" psp_muxer_select="mov_muxer" rtp_demuxer_select="sdp_demuxer" +rtp_muxer_select="mpegvideo" rtpdec_select="asf_demuxer rm_demuxer rtp_protocol mpegts_demuxer mov_demuxer" rtsp_demuxer_select="http_protocol rtpdec" rtsp_muxer_select="rtp_muxer http_protocol rtp_protocol" diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 9bff68f83e..6dde8a64f4 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -50,6 +50,7 @@ OBJS-$(CONFIG_MDCT) += mdct_fixed.o mdct_float.o OBJS-$(CONFIG_MPEGAUDIODSP) += mpegaudiodsp.o \ mpegaudiodsp_fixed.o \ mpegaudiodsp_float.o +OBJS-$(CONFIG_MPEGVIDEO) += mpegvideo.o RDFT-OBJS-$(CONFIG_HARDCODED_TABLES) += sin_tables.o OBJS-$(CONFIG_RDFT) += rdft.o $(RDFT-OBJS-yes) OBJS-$(CONFIG_SINEWIN) += sinewin.o @@ -111,7 +112,7 @@ OBJS-$(CONFIG_BMV_VIDEO_DECODER) += bmv.o OBJS-$(CONFIG_BMV_AUDIO_DECODER) += bmv.o OBJS-$(CONFIG_C93_DECODER) += c93.o OBJS-$(CONFIG_CAVS_DECODER) += cavs.o cavsdec.o cavsdsp.o \ - mpeg12data.o mpegvideo.o + mpeg12data.o OBJS-$(CONFIG_CDGRAPHICS_DECODER) += cdgraphics.o OBJS-$(CONFIG_CDXL_DECODER) += cdxl.o OBJS-$(CONFIG_CINEPAK_DECODER) += cinepak.o @@ -127,8 +128,7 @@ OBJS-$(CONFIG_DFA_DECODER) += dfa.o OBJS-$(CONFIG_DNXHD_DECODER) += dnxhddec.o dnxhddata.o OBJS-$(CONFIG_DNXHD_ENCODER) += dnxhdenc.o dnxhddata.o \ mpegvideo_enc.o motion_est.o \ - ratecontrol.o mpeg12data.o \ - mpegvideo.o + ratecontrol.o mpeg12data.o OBJS-$(CONFIG_DPX_DECODER) += dpx.o OBJS-$(CONFIG_DPX_ENCODER) += dpxenc.o OBJS-$(CONFIG_DSICINAUDIO_DECODER) += dsicinav.o @@ -146,13 +146,11 @@ OBJS-$(CONFIG_EAC3_ENCODER) += eac3enc.o ac3enc.o ac3enc_float.o \ ac3tab.o ac3.o kbdwin.o eac3_data.o OBJS-$(CONFIG_EACMV_DECODER) += eacmv.o OBJS-$(CONFIG_EAMAD_DECODER) += eamad.o eaidct.o mpeg12.o \ - mpeg12data.o mpegvideo.o \ - error_resilience.o + mpeg12data.o error_resilience.o OBJS-$(CONFIG_EATGQ_DECODER) += eatgq.o eaidct.o OBJS-$(CONFIG_EATGV_DECODER) += eatgv.o OBJS-$(CONFIG_EATQI_DECODER) += eatqi.o eaidct.o mpeg12.o \ - mpeg12data.o mpegvideo.o \ - error_resilience.o + mpeg12data.o error_resilience.o OBJS-$(CONFIG_EIGHTBPS_DECODER) += 8bps.o OBJS-$(CONFIG_EIGHTSVX_EXP_DECODER) += 8svx.o OBJS-$(CONFIG_EIGHTSVX_FIB_DECODER) += 8svx.o @@ -176,27 +174,24 @@ OBJS-$(CONFIG_GIF_DECODER) += gifdec.o lzw.o OBJS-$(CONFIG_GIF_ENCODER) += gif.o lzwenc.o OBJS-$(CONFIG_GSM_DECODER) += gsmdec.o gsmdec_data.o msgsmdec.o OBJS-$(CONFIG_GSM_MS_DECODER) += gsmdec.o gsmdec_data.o msgsmdec.o -OBJS-$(CONFIG_H261_DECODER) += h261dec.o h261.o \ - mpegvideo.o error_resilience.o +OBJS-$(CONFIG_H261_DECODER) += h261dec.o h261.o error_resilience.o OBJS-$(CONFIG_H261_ENCODER) += h261enc.o h261.o \ mpegvideo_enc.o motion_est.o \ - ratecontrol.o mpeg12data.o \ - mpegvideo.o + ratecontrol.o mpeg12data.o OBJS-$(CONFIG_H263_DECODER) += h263dec.o h263.o ituh263dec.o \ mpeg4video.o mpeg4videodec.o flvdec.o\ - intelh263dec.o mpegvideo.o \ - error_resilience.o + intelh263dec.o error_resilience.o OBJS-$(CONFIG_H263_VAAPI_HWACCEL) += vaapi_mpeg4.o OBJS-$(CONFIG_H263_ENCODER) += mpegvideo_enc.o mpeg4video.o \ mpeg4videoenc.o motion_est.o \ ratecontrol.o h263.o ituh263enc.o \ flvenc.o mpeg12data.o \ - mpegvideo.o error_resilience.o + error_resilience.o OBJS-$(CONFIG_H264_DECODER) += h264.o \ h264_loopfilter.o h264_direct.o \ cabac.o h264_sei.o h264_ps.o \ h264_refs.o h264_cavlc.o h264_cabac.o\ - mpegvideo.o error_resilience.o + error_resilience.o OBJS-$(CONFIG_H264_DXVA2_HWACCEL) += dxva2_h264.o OBJS-$(CONFIG_H264_VAAPI_HWACCEL) += vaapi_h264.o OBJS-$(CONFIG_H264_VDA_HWACCEL) += vda_h264.o @@ -222,19 +217,17 @@ OBJS-$(CONFIG_KMVC_DECODER) += kmvc.o OBJS-$(CONFIG_LAGARITH_DECODER) += lagarith.o lagarithrac.o OBJS-$(CONFIG_LJPEG_ENCODER) += ljpegenc.o mjpegenc.o mjpeg.o \ mpegvideo_enc.o motion_est.o \ - ratecontrol.o mpeg12data.o \ - mpegvideo.o + ratecontrol.o mpeg12data.o OBJS-$(CONFIG_LOCO_DECODER) += loco.o OBJS-$(CONFIG_MACE3_DECODER) += mace.o OBJS-$(CONFIG_MACE6_DECODER) += mace.o OBJS-$(CONFIG_MDEC_DECODER) += mdec.o mpeg12.o mpeg12data.o \ - mpegvideo.o error_resilience.o + error_resilience.o OBJS-$(CONFIG_MIMIC_DECODER) += mimic.o OBJS-$(CONFIG_MJPEG_DECODER) += mjpegdec.o mjpeg.o OBJS-$(CONFIG_MJPEG_ENCODER) += mjpegenc.o mjpeg.o \ mpegvideo_enc.o motion_est.o \ - ratecontrol.o mpeg12data.o \ - mpegvideo.o + ratecontrol.o mpeg12data.o OBJS-$(CONFIG_MJPEGB_DECODER) += mjpegbdec.o mjpegdec.o mjpeg.o OBJS-$(CONFIG_MLP_DECODER) += mlpdec.o mlpdsp.o OBJS-$(CONFIG_MMVIDEO_DECODER) += mmvideo.o @@ -271,19 +264,19 @@ OBJS-$(CONFIG_MPC8_DECODER) += mpc8.o mpc.o mpegaudiodec.o \ mpegaudiodata.o OBJS-$(CONFIG_MPEG_XVMC_DECODER) += mpegvideo_xvmc.o OBJS-$(CONFIG_MPEG1VIDEO_DECODER) += mpeg12.o mpeg12data.o \ - mpegvideo.o error_resilience.o + error_resilience.o OBJS-$(CONFIG_MPEG1VIDEO_ENCODER) += mpeg12enc.o mpegvideo_enc.o \ motion_est.o ratecontrol.o \ mpeg12.o mpeg12data.o \ - mpegvideo.o error_resilience.o + error_resilience.o OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL) += dxva2_mpeg2.o OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL) += vaapi_mpeg2.o OBJS-$(CONFIG_MPEG2VIDEO_DECODER) += mpeg12.o mpeg12data.o \ - mpegvideo.o error_resilience.o + error_resilience.o OBJS-$(CONFIG_MPEG2VIDEO_ENCODER) += mpeg12enc.o mpegvideo_enc.o \ motion_est.o ratecontrol.o \ mpeg12.o mpeg12data.o \ - mpegvideo.o error_resilience.o + error_resilience.o OBJS-$(CONFIG_MPEG4_VAAPI_HWACCEL) += vaapi_mpeg4.o OBJS-$(CONFIG_MSMPEG4V1_DECODER) += msmpeg4.o msmpeg4data.o OBJS-$(CONFIG_MSMPEG4V2_DECODER) += msmpeg4.o msmpeg4data.o h263dec.o \ @@ -356,9 +349,9 @@ OBJS-$(CONFIG_RV10_ENCODER) += rv10enc.o OBJS-$(CONFIG_RV20_DECODER) += rv10.o OBJS-$(CONFIG_RV20_ENCODER) += rv20enc.o OBJS-$(CONFIG_RV30_DECODER) += rv30.o rv34.o rv30dsp.o rv34dsp.o \ - mpegvideo.o error_resilience.o + error_resilience.o OBJS-$(CONFIG_RV40_DECODER) += rv40.o rv34.o rv34dsp.o rv40dsp.o \ - mpegvideo.o error_resilience.o + error_resilience.o OBJS-$(CONFIG_S302M_DECODER) += s302m.o OBJS-$(CONFIG_SGI_DECODER) += sgidec.o OBJS-$(CONFIG_SGI_ENCODER) += sgienc.o rle.o @@ -373,7 +366,7 @@ OBJS-$(CONFIG_SMC_DECODER) += smc.o OBJS-$(CONFIG_SNOW_DECODER) += snowdec.o snow.o rangecoder.o OBJS-$(CONFIG_SNOW_ENCODER) += snowenc.o snow.o rangecoder.o \ motion_est.o ratecontrol.o \ - h263.o mpegvideo.o \ + h263.o \ error_resilience.o ituh263enc.o \ mpegvideo_enc.o mpeg12data.o OBJS-$(CONFIG_SOL_DPCM_DECODER) += dpcm.o @@ -382,17 +375,17 @@ OBJS-$(CONFIG_SRT_DECODER) += srtdec.o ass.o OBJS-$(CONFIG_SUNRAST_DECODER) += sunrast.o OBJS-$(CONFIG_SUNRAST_ENCODER) += sunrastenc.o OBJS-$(CONFIG_SVQ1_DECODER) += svq1dec.o svq1.o h263.o \ - mpegvideo.o error_resilience.o + error_resilience.o OBJS-$(CONFIG_SVQ1_ENCODER) += svq1enc.o svq1.o \ motion_est.o h263.o \ - mpegvideo.o error_resilience.o \ + error_resilience.o \ ituh263enc.o mpegvideo_enc.o \ ratecontrol.o mpeg12data.o OBJS-$(CONFIG_SVQ3_DECODER) += h264.o svq3.o \ h264_loopfilter.o h264_direct.o \ h264_sei.o h264_ps.o h264_refs.o \ h264_cavlc.o h264_cabac.o cabac.o \ - mpegvideo.o error_resilience.o \ + error_resilience.o \ svq1dec.o svq1.o h263.o OBJS-$(CONFIG_TARGA_DECODER) += targa.o OBJS-$(CONFIG_TARGA_ENCODER) += targaenc.o rle.o @@ -589,14 +582,14 @@ OBJS-$(CONFIG_MP2_MUXER) += mpegaudiodata.o mpegaudiodecheader.o OBJS-$(CONFIG_MP3_MUXER) += mpegaudiodata.o mpegaudiodecheader.o OBJS-$(CONFIG_MOV_DEMUXER) += mpeg4audio.o mpegaudiodata.o ac3tab.o OBJS-$(CONFIG_MOV_MUXER) += mpeg4audio.o mpegaudiodata.o -OBJS-$(CONFIG_MPEGTS_MUXER) += mpegvideo.o mpeg4audio.o +OBJS-$(CONFIG_MPEGTS_MUXER) += mpeg4audio.o OBJS-$(CONFIG_MPEGTS_DEMUXER) += mpeg4audio.o mpegaudiodata.o OBJS-$(CONFIG_NUT_MUXER) += mpegaudiodata.o OBJS-$(CONFIG_OGG_DEMUXER) += xiph.o flac.o flacdata.o \ mpeg12data.o vorbis_parser.o \ dirac.o OBJS-$(CONFIG_OGG_MUXER) += xiph.o flac.o flacdata.o -OBJS-$(CONFIG_RTP_MUXER) += mpeg4audio.o mpegvideo.o xiph.o +OBJS-$(CONFIG_RTP_MUXER) += mpeg4audio.o xiph.o OBJS-$(CONFIG_SPDIF_DEMUXER) += aacadtsdec.o mpeg4audio.o OBJS-$(CONFIG_SPDIF_MUXER) += dca.o OBJS-$(CONFIG_WEBM_MUXER) += mpeg4audio.o mpegaudiodata.o \ @@ -658,25 +651,25 @@ OBJS-$(CONFIG_H264_PARSER) += h264_parser.o h264.o \ h264_refs.o h264_sei.o h264_direct.o \ h264_loopfilter.o h264_cabac.o \ h264_cavlc.o h264_ps.o \ - mpegvideo.o error_resilience.o + error_resilience.o OBJS-$(CONFIG_AAC_LATM_PARSER) += latm_parser.o OBJS-$(CONFIG_MJPEG_PARSER) += mjpeg_parser.o OBJS-$(CONFIG_MLP_PARSER) += mlp_parser.o mlp.o OBJS-$(CONFIG_MPEG4VIDEO_PARSER) += mpeg4video_parser.o h263.o \ - mpegvideo.o error_resilience.o \ + error_resilience.o \ mpeg4videodec.o mpeg4video.o \ ituh263dec.o h263dec.o OBJS-$(CONFIG_MPEGAUDIO_PARSER) += mpegaudio_parser.o \ mpegaudiodecheader.o mpegaudiodata.o OBJS-$(CONFIG_MPEGVIDEO_PARSER) += mpegvideo_parser.o \ mpeg12.o mpeg12data.o \ - mpegvideo.o error_resilience.o + error_resilience.o OBJS-$(CONFIG_PNM_PARSER) += pnm_parser.o pnm.o OBJS-$(CONFIG_RV30_PARSER) += rv34_parser.o OBJS-$(CONFIG_RV40_PARSER) += rv34_parser.o OBJS-$(CONFIG_VC1_PARSER) += vc1_parser.o vc1.o vc1data.o \ msmpeg4.o msmpeg4data.o mpeg4video.o \ - h263.o mpegvideo.o error_resilience.o + h263.o error_resilience.o OBJS-$(CONFIG_VORBIS_PARSER) += vorbis_parser.o xiph.o OBJS-$(CONFIG_VP3_PARSER) += vp3_parser.o OBJS-$(CONFIG_VP8_PARSER) += vp8_parser.o From 7a851153d3fe1a9e0d60bf11053870d1ea8241e6 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Sat, 4 Aug 2012 00:50:21 +0100 Subject: [PATCH 15/16] mpegvideo: convert mpegvideo_common.h to a .c file This file defines a single, huge function, MPV_motion(), which although being declared inline is not actually inlined by the compiler (for good reason). There is thus no sense in defining this function in a header file, resulting in multiple copies of it in the final library. Signed-off-by: Mans Rullgard --- libavcodec/Makefile | 2 +- libavcodec/dnxhdenc.c | 1 - libavcodec/mpegvideo.c | 5 ++-- libavcodec/mpegvideo.h | 15 ++++++++++ libavcodec/mpegvideo_enc.c | 11 +++---- ...{mpegvideo_common.h => mpegvideo_motion.c} | 30 ++++--------------- 6 files changed, 30 insertions(+), 34 deletions(-) rename libavcodec/{mpegvideo_common.h => mpegvideo_motion.c} (97%) diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 6dde8a64f4..655e828cbc 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -50,7 +50,7 @@ OBJS-$(CONFIG_MDCT) += mdct_fixed.o mdct_float.o OBJS-$(CONFIG_MPEGAUDIODSP) += mpegaudiodsp.o \ mpegaudiodsp_fixed.o \ mpegaudiodsp_float.o -OBJS-$(CONFIG_MPEGVIDEO) += mpegvideo.o +OBJS-$(CONFIG_MPEGVIDEO) += mpegvideo.o mpegvideo_motion.o RDFT-OBJS-$(CONFIG_HARDCODED_TABLES) += sin_tables.o OBJS-$(CONFIG_RDFT) += rdft.o $(RDFT-OBJS-yes) OBJS-$(CONFIG_SINEWIN) += sinewin.o diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c index aca54974f7..523d1c078f 100644 --- a/libavcodec/dnxhdenc.c +++ b/libavcodec/dnxhdenc.c @@ -31,7 +31,6 @@ #include "dsputil.h" #include "internal.h" #include "mpegvideo.h" -#include "mpegvideo_common.h" #include "dnxhdenc.h" #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 4fb5949131..8f3544fa1a 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -33,7 +33,6 @@ #include "dsputil.h" #include "internal.h" #include "mpegvideo.h" -#include "mpegvideo_common.h" #include "mjpegenc.h" #include "msmpeg4.h" #include "xvmc_internal.h" @@ -2035,12 +2034,12 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64], op_pix = s->dsp.put_no_rnd_pixels_tab; } if (s->mv_dir & MV_DIR_FORWARD) { - MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.f.data, op_pix, op_qpix); + ff_MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.f.data, op_pix, op_qpix); op_pix = s->dsp.avg_pixels_tab; op_qpix= s->me.qpel_avg; } if (s->mv_dir & MV_DIR_BACKWARD) { - MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.f.data, op_pix, op_qpix); + ff_MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.f.data, op_pix, op_qpix); } } diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 5c537da38f..80fa0fa1bd 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -739,6 +739,13 @@ static const AVClass name ## _class = {\ .version = LIBAVUTIL_VERSION_INT,\ }; +/** + * Set the given MpegEncContext to common defaults (same for encoding + * and decoding). The changed fields will not depend upon the prior + * state of the MpegEncContext. + */ +void ff_MPV_common_defaults(MpegEncContext *s); + void ff_MPV_decode_defaults(MpegEncContext *s); int ff_MPV_common_init(MpegEncContext *s); void ff_MPV_common_end(MpegEncContext *s); @@ -777,10 +784,18 @@ void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int en int ff_dct_common_init(MpegEncContext *s); void ff_convert_matrix(DSPContext *dsp, int (*qmat)[64], uint16_t (*qmat16)[2][64], const uint16_t *quant_matrix, int bias, int qmin, int qmax, int intra); +int ff_dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); void ff_init_block_index(MpegEncContext *s); void ff_copy_picture(Picture *dst, Picture *src); +void ff_MPV_motion(MpegEncContext *s, + uint8_t *dest_y, uint8_t *dest_cb, + uint8_t *dest_cr, int dir, + uint8_t **ref_picture, + op_pixels_func (*pix_op)[4], + qpel_mc_func (*qpix_op)[16]); + /** * Allocate a Picture. * The pixels are allocated/set by calling get_buffer() if shared = 0. diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index e84b0dae03..d527ace6dd 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -33,7 +33,6 @@ #include "avcodec.h" #include "dsputil.h" #include "mpegvideo.h" -#include "mpegvideo_common.h" #include "h263.h" #include "mjpegenc.h" #include "msmpeg4.h" @@ -1850,14 +1849,16 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s, } if (s->mv_dir & MV_DIR_FORWARD) { - MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.f.data, - op_pix, op_qpix); + ff_MPV_motion(s, dest_y, dest_cb, dest_cr, 0, + s->last_picture.f.data, + op_pix, op_qpix); op_pix = s->dsp.avg_pixels_tab; op_qpix = s->dsp.avg_qpel_pixels_tab; } if (s->mv_dir & MV_DIR_BACKWARD) { - MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.f.data, - op_pix, op_qpix); + ff_MPV_motion(s, dest_y, dest_cb, dest_cr, 1, + s->next_picture.f.data, + op_pix, op_qpix); } if (s->flags & CODEC_FLAG_INTERLACED_DCT) { diff --git a/libavcodec/mpegvideo_common.h b/libavcodec/mpegvideo_motion.c similarity index 97% rename from libavcodec/mpegvideo_common.h rename to libavcodec/mpegvideo_motion.c index 224ec9887a..ea0695323b 100644 --- a/libavcodec/mpegvideo_common.h +++ b/libavcodec/mpegvideo_motion.c @@ -1,5 +1,4 @@ /* - * The simplest mpeg encoder (well, it was the simplest!) * Copyright (c) 2000,2001 Fabrice Bellard * Copyright (c) 2002-2004 Michael Niedermayer * @@ -22,14 +21,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/** - * @file - * The simplest mpeg encoder (well, it was the simplest!). - */ - -#ifndef AVCODEC_MPEGVIDEO_COMMON_H -#define AVCODEC_MPEGVIDEO_COMMON_H - #include #include "avcodec.h" #include "dsputil.h" @@ -38,14 +29,6 @@ #include "msmpeg4.h" #include -int ff_dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); - -/** - * Set the given MpegEncContext to common defaults (same for encoding and decoding). - * The changed fields will not depend upon the prior state of the MpegEncContext. - */ -void ff_MPV_common_defaults(MpegEncContext *s); - static inline void gmc1_motion(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, uint8_t **ref_picture) @@ -874,12 +857,12 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s, } } -static inline void MPV_motion(MpegEncContext *s, - uint8_t *dest_y, uint8_t *dest_cb, - uint8_t *dest_cr, int dir, - uint8_t **ref_picture, - op_pixels_func (*pix_op)[4], - qpel_mc_func (*qpix_op)[16]) +void ff_MPV_motion(MpegEncContext *s, + uint8_t *dest_y, uint8_t *dest_cb, + uint8_t *dest_cr, int dir, + uint8_t **ref_picture, + op_pixels_func (*pix_op)[4], + qpel_mc_func (*qpix_op)[16]) { #if !CONFIG_SMALL if(s->out_format == FMT_MPEG1) @@ -890,4 +873,3 @@ static inline void MPV_motion(MpegEncContext *s, MPV_motion_internal(s, dest_y, dest_cb, dest_cr, dir, ref_picture, pix_op, qpix_op, 0); } -#endif /* AVCODEC_MPEGVIDEO_COMMON_H */ From f69f4036f8cc3b673864dce01d2714fd5e49e8da Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Sat, 4 Aug 2012 02:30:02 +0100 Subject: [PATCH 16/16] mpegvideo: reduce excessive inlining of mpeg_motion() The main benefit of inlining this function is from constant propagation for the 'field_based' argument. Instead of inlining all calls, create two versions of the function for field_based values of 0 and 1. Signed-off-by: Mans Rullgard --- libavcodec/mpegvideo_motion.c | 67 ++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/libavcodec/mpegvideo_motion.c b/libavcodec/mpegvideo_motion.c index ea0695323b..d4c4d6e640 100644 --- a/libavcodec/mpegvideo_motion.c +++ b/libavcodec/mpegvideo_motion.c @@ -339,21 +339,39 @@ if(s->quarter_sample) } } /* apply one mpeg motion vector to the three components */ -static av_always_inline -void mpeg_motion(MpegEncContext *s, - uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, - int field_based, int bottom_field, int field_select, - uint8_t **ref_picture, op_pixels_func (*pix_op)[4], - int motion_x, int motion_y, int h, int mb_y) +static void mpeg_motion(MpegEncContext *s, + uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, + int field_select, uint8_t **ref_picture, + op_pixels_func (*pix_op)[4], + int motion_x, int motion_y, int h, int mb_y) { #if !CONFIG_SMALL if(s->out_format == FMT_MPEG1) - mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, field_based, + mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, 0, 0, + field_select, ref_picture, pix_op, + motion_x, motion_y, h, 1, mb_y); + else +#endif + mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, 0, 0, + field_select, ref_picture, pix_op, + motion_x, motion_y, h, 0, mb_y); +} + +static void mpeg_motion_field(MpegEncContext *s, uint8_t *dest_y, + uint8_t *dest_cb, uint8_t *dest_cr, + int bottom_field, int field_select, + uint8_t **ref_picture, + op_pixels_func (*pix_op)[4], + int motion_x, int motion_y, int h, int mb_y) +{ +#if !CONFIG_SMALL + if(s->out_format == FMT_MPEG1) + mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, 1, bottom_field, field_select, ref_picture, pix_op, motion_x, motion_y, h, 1, mb_y); else #endif - mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, field_based, + mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, 1, bottom_field, field_select, ref_picture, pix_op, motion_x, motion_y, h, 0, mb_y); } @@ -708,8 +726,7 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s, s->mv[dir][0][0], s->mv[dir][0][1], 16); }else { - mpeg_motion(s, dest_y, dest_cb, dest_cr, - 0, 0, 0, + mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, ref_picture, pix_op, s->mv[dir][0][0], s->mv[dir][0][1], 16, mb_y); } @@ -782,15 +799,15 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s, } }else{ /* top field */ - mpeg_motion(s, dest_y, dest_cb, dest_cr, - 1, 0, s->field_select[dir][0], - ref_picture, pix_op, - s->mv[dir][0][0], s->mv[dir][0][1], 8, mb_y); + mpeg_motion_field(s, dest_y, dest_cb, dest_cr, + 0, s->field_select[dir][0], + ref_picture, pix_op, + s->mv[dir][0][0], s->mv[dir][0][1], 8, mb_y); /* bottom field */ - mpeg_motion(s, dest_y, dest_cb, dest_cr, - 1, 1, s->field_select[dir][1], - ref_picture, pix_op, - s->mv[dir][1][0], s->mv[dir][1][1], 8, mb_y); + mpeg_motion_field(s, dest_y, dest_cb, dest_cr, + 1, s->field_select[dir][1], + ref_picture, pix_op, + s->mv[dir][1][0], s->mv[dir][1][1], 8, mb_y); } } else { if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != AV_PICTURE_TYPE_B && !s->first_field){ @@ -798,7 +815,7 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s, } mpeg_motion(s, dest_y, dest_cb, dest_cr, - 0, 0, s->field_select[dir][0], + s->field_select[dir][0], ref_picture, pix_op, s->mv[dir][0][0], s->mv[dir][0][1], 16, mb_y>>1); } @@ -815,7 +832,7 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s, } mpeg_motion(s, dest_y, dest_cb, dest_cr, - 0, 0, s->field_select[dir][i], + s->field_select[dir][i], ref2picture, pix_op, s->mv[dir][i][0], s->mv[dir][i][1] + 16*i, 8, mb_y>>1); @@ -829,17 +846,17 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s, for(i=0; i<2; i++){ int j; for(j=0; j<2; j++){ - mpeg_motion(s, dest_y, dest_cb, dest_cr, - 1, j, j^i, - ref_picture, pix_op, - s->mv[dir][2*i + j][0], s->mv[dir][2*i + j][1], 8, mb_y); + mpeg_motion_field(s, dest_y, dest_cb, dest_cr, + j, j^i, ref_picture, pix_op, + s->mv[dir][2*i + j][0], + s->mv[dir][2*i + j][1], 8, mb_y); } pix_op = s->dsp.avg_pixels_tab; } }else{ for(i=0; i<2; i++){ mpeg_motion(s, dest_y, dest_cb, dest_cr, - 0, 0, s->picture_structure != i+1, + s->picture_structure != i+1, ref_picture, pix_op, s->mv[dir][2*i][0],s->mv[dir][2*i][1],16, mb_y>>1);