From f70381ab9d53132be2d009d6db9649b3cad8288b Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 31 Oct 2012 22:32:36 +0100 Subject: a64: remove interleaved mode. It has been disabled since it was added two years ago. --- libavformat/a64.c | 116 +----------------------------------------------------- 1 file changed, 2 insertions(+), 114 deletions(-) (limited to 'libavformat') diff --git a/libavformat/a64.c b/libavformat/a64.c index 56b9a446db..15a0475703 100644 --- a/libavformat/a64.c +++ b/libavformat/a64.c @@ -23,17 +23,11 @@ #include "libavcodec/a64enc.h" #include "libavcodec/bytestream.h" #include "avformat.h" - -typedef struct A64MuxerContext { - int interleaved; - AVPacket prev_pkt; - int prev_frame_count; -} A64MuxerContext; +#include "rawenc.h" static int a64_write_header(struct AVFormatContext *s) { AVCodecContext *avctx = s->streams[0]->codec; - A64MuxerContext *c = s->priv_data; uint8_t header[5] = { 0x00, //load 0x40, //address @@ -41,7 +35,6 @@ static int a64_write_header(struct AVFormatContext *s) 0x00, //charset_lifetime (multi only) 0x00 //fps in 50/fps; }; - c->interleaved = 0; switch (avctx->codec->id) { case AV_CODEC_ID_A64_MULTI: header[2] = 0x00; @@ -57,109 +50,6 @@ static int a64_write_header(struct AVFormatContext *s) return AVERROR(EINVAL); } avio_write(s->pb, header, 2); - c->prev_pkt.size = 0; - c->prev_frame_count = 0; - return 0; -} - -static int a64_write_packet(struct AVFormatContext *s, AVPacket *pkt) -{ - AVCodecContext *avctx = s->streams[0]->codec; - A64MuxerContext *c = s->priv_data; - int i, j; - int ch_chunksize; - int lifetime; - int frame_count; - int charset_size; - int frame_size; - int num_frames; - - /* fetch values from extradata */ - switch (avctx->codec->id) { - case AV_CODEC_ID_A64_MULTI: - case AV_CODEC_ID_A64_MULTI5: - if(c->interleaved) { - /* Write interleaved, means we insert chunks of the future charset before each current frame. - * Reason: if we load 1 charset + corresponding frames in one block on c64, we need to store - * them first and then display frame by frame to keep in sync. Thus we would read and write - * the data for colram from/to ram first and waste too much time. If we interleave and send the - * charset beforehand, we assemble a new charset chunk by chunk, write current screen data to - * screen-ram to be displayed and decode the colram directly to colram-location $d800 during - * the overscan, while reading directly from source. - * This is the only way so far, to achieve 25fps on c64 */ - if(avctx->extradata) { - /* fetch values from extradata */ - lifetime = AV_RB32(avctx->extradata + 0); - frame_count = AV_RB32(avctx->extradata + 4); - charset_size = AV_RB32(avctx->extradata + 8); - frame_size = AV_RB32(avctx->extradata + 12); - - /* TODO: sanity checks? */ - } else { - av_log(avctx, AV_LOG_ERROR, "extradata not set\n"); - return AVERROR(EINVAL); - } - - ch_chunksize=charset_size/lifetime; - /* TODO: check if charset/size is % lifetime, but maybe check in codec */ - - if(pkt->data) num_frames = lifetime; - else num_frames = c->prev_frame_count; - - for(i = 0; i < num_frames; i++) { - if(pkt->data) { - /* if available, put newest charset chunk into buffer */ - avio_write(s->pb, pkt->data + ch_chunksize * i, ch_chunksize); - } else { - /* a bit ugly, but is there an alternative to put many zeros? */ - for(j = 0; j < ch_chunksize; j++) avio_w8(s->pb, 0); - } - - if(c->prev_pkt.data) { - /* put frame (screen + colram) from last packet into buffer */ - avio_write(s->pb, c->prev_pkt.data + charset_size + frame_size * i, frame_size); - } else { - /* a bit ugly, but is there an alternative to put many zeros? */ - for(j = 0; j < frame_size; j++) avio_w8(s->pb, 0); - } - } - - /* backup current packet for next turn */ - if(pkt->data) { - /* no backup packet yet? create one! */ - if(!c->prev_pkt.data) av_new_packet(&c->prev_pkt, pkt->size); - /* we have a packet and data is big enough, reuse it */ - if(c->prev_pkt.data && c->prev_pkt.size >= pkt->size) { - memcpy(c->prev_pkt.data, pkt->data, pkt->size); - c->prev_pkt.size = pkt->size; - } else { - av_log(avctx, AV_LOG_ERROR, "Too less memory for prev_pkt.\n"); - return AVERROR(ENOMEM); - } - } - - c->prev_frame_count = frame_count; - break; - } - default: - /* Write things as is. Nice for self-contained frames from non-multicolor modes or if played - * directly from ram and not from a streaming device (rrnet/mmc) */ - if(pkt) avio_write(s->pb, pkt->data, pkt->size); - break; - } - - avio_flush(s->pb); - return 0; -} - -static int a64_write_trailer(struct AVFormatContext *s) -{ - A64MuxerContext *c = s->priv_data; - AVPacket pkt = {0}; - /* need to flush last packet? */ - if(c->interleaved) a64_write_packet(s, &pkt); - /* discard backed up packet */ - if(c->prev_pkt.data) av_destruct_packet(&c->prev_pkt); return 0; } @@ -167,9 +57,7 @@ AVOutputFormat ff_a64_muxer = { .name = "a64", .long_name = NULL_IF_CONFIG_SMALL("a64 - video for Commodore 64"), .extensions = "a64, A64", - .priv_data_size = sizeof (A64Context), .video_codec = AV_CODEC_ID_A64_MULTI, .write_header = a64_write_header, - .write_packet = a64_write_packet, - .write_trailer = a64_write_trailer, + .write_packet = ff_raw_write_packet, }; -- cgit v1.2.3 From 179a5c37e070f619f14289bdc0fa66a08219eed9 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 1 Nov 2012 14:03:04 +0100 Subject: rtpdec: factorize identical code used in several handlers --- libavformat/rtpdec.c | 11 +++++++++++ libavformat/rtpdec.h | 5 +++++ libavformat/rtpdec_h263_rfc2190.c | 12 +++++------- libavformat/rtpdec_jpeg.c | 13 +++---------- libavformat/rtpdec_svq3.c | 9 ++++----- libavformat/rtpdec_vp8.c | 13 +++---------- libavformat/rtpdec_xiph.c | 13 +++---------- 7 files changed, 34 insertions(+), 42 deletions(-) (limited to 'libavformat') diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c index d16122d40d..a305dd6957 100644 --- a/libavformat/rtpdec.c +++ b/libavformat/rtpdec.c @@ -803,3 +803,14 @@ int ff_parse_fmtp(AVStream *stream, PayloadContext *data, const char *p, av_free(value); return 0; } + +int ff_rtp_finalize_packet(AVPacket *pkt, AVIOContext **dyn_buf, int stream_idx) +{ + av_init_packet(pkt); + + pkt->size = avio_close_dyn_buf(*dyn_buf, &pkt->data); + pkt->stream_index = stream_idx; + pkt->destruct = av_destruct_packet; + *dyn_buf = NULL; + return pkt->size; +} diff --git a/libavformat/rtpdec.h b/libavformat/rtpdec.h index 7f14aa2d68..da3680d6ab 100644 --- a/libavformat/rtpdec.h +++ b/libavformat/rtpdec.h @@ -202,4 +202,9 @@ int ff_parse_fmtp(AVStream *stream, PayloadContext *data, const char *p, void av_register_rtp_dynamic_payload_handlers(void); +/** + * Close the dynamic buffer and make a packet from it. + */ +int ff_rtp_finalize_packet(AVPacket *pkt, AVIOContext **dyn_buf, int stream_idx); + #endif /* AVFORMAT_RTPDEC_H */ diff --git a/libavformat/rtpdec_h263_rfc2190.c b/libavformat/rtpdec_h263_rfc2190.c index 163d4eaba7..4957b337c7 100644 --- a/libavformat/rtpdec_h263_rfc2190.c +++ b/libavformat/rtpdec_h263_rfc2190.c @@ -61,7 +61,7 @@ static int h263_handle_packet(AVFormatContext *ctx, PayloadContext *data, { /* Corresponding to header fields in the RFC */ int f, p, i, sbit, ebit, src, r; - int header_size; + int header_size, ret; if (data->newformat) return ff_h263_handle_packet(ctx, data, st, pkt, timestamp, buf, len, @@ -133,7 +133,7 @@ static int h263_handle_packet(AVFormatContext *ctx, PayloadContext *data, /* Check the picture start code, only start buffering a new frame * if this is correct */ if (len > 4 && AV_RB32(buf) >> 10 == 0x20) { - int ret = avio_open_dyn_buf(&data->buf); + ret = avio_open_dyn_buf(&data->buf); if (ret < 0) return ret; data->timestamp = *timestamp; @@ -185,13 +185,11 @@ static int h263_handle_packet(AVFormatContext *ctx, PayloadContext *data, avio_w8(data->buf, data->endbyte); data->endbyte_bits = 0; - av_init_packet(pkt); - pkt->size = avio_close_dyn_buf(data->buf, &pkt->data); - pkt->destruct = av_destruct_packet; - pkt->stream_index = st->index; + ret = ff_rtp_finalize_packet(pkt, &data->buf, st->index); + if (ret < 0) + return ret; if (!i) pkt->flags |= AV_PKT_FLAG_KEY; - data->buf = NULL; return 0; } diff --git a/libavformat/rtpdec_jpeg.c b/libavformat/rtpdec_jpeg.c index 944758d4fc..9f73f7d5dc 100644 --- a/libavformat/rtpdec_jpeg.c +++ b/libavformat/rtpdec_jpeg.c @@ -20,6 +20,7 @@ */ #include "avformat.h" +#include "rtpdec.h" #include "rtpdec_formats.h" #include "libavutil/intreadwrite.h" #include "libavcodec/mjpeg.h" @@ -367,19 +368,11 @@ static int jpeg_parse_packet(AVFormatContext *ctx, PayloadContext *jpeg, avio_write(jpeg->frame, buf, sizeof(buf)); /* Prepare the JPEG packet. */ - av_init_packet(pkt); - pkt->size = avio_close_dyn_buf(jpeg->frame, &pkt->data); - if (pkt->size < 0) { + if ((ret = ff_rtp_finalize_packet(pkt, &jpeg->frame, st->index)) < 0) { av_log(ctx, AV_LOG_ERROR, "Error occured when getting frame buffer.\n"); - jpeg->frame = NULL; - return pkt->size; + return ret; } - pkt->stream_index = st->index; - pkt->destruct = av_destruct_packet; - - /* Re-init the frame buffer. */ - jpeg->frame = NULL; return 0; } diff --git a/libavformat/rtpdec_svq3.c b/libavformat/rtpdec_svq3.c index bfc602ebb2..087a1e3346 100644 --- a/libavformat/rtpdec_svq3.c +++ b/libavformat/rtpdec_svq3.c @@ -97,12 +97,11 @@ static int svq3_parse_packet (AVFormatContext *s, PayloadContext *sv, avio_write(sv->pktbuf, buf, len); if (end_packet) { - av_init_packet(pkt); - pkt->stream_index = st->index; + int ret = ff_rtp_finalize_packet(pkt, &sv->pktbuf, st->index); + if (ret < 0) + return ret; + *timestamp = sv->timestamp; - pkt->size = avio_close_dyn_buf(sv->pktbuf, &pkt->data); - pkt->destruct = av_destruct_packet; - sv->pktbuf = NULL; return 0; } diff --git a/libavformat/rtpdec_vp8.c b/libavformat/rtpdec_vp8.c index a52be4b644..541a1bcd96 100644 --- a/libavformat/rtpdec_vp8.c +++ b/libavformat/rtpdec_vp8.c @@ -36,15 +36,6 @@ struct PayloadContext { uint32_t timestamp; }; -static void prepare_packet(AVPacket *pkt, PayloadContext *vp8, int stream) -{ - av_init_packet(pkt); - pkt->stream_index = stream; - pkt->size = avio_close_dyn_buf(vp8->data, &pkt->data); - pkt->destruct = av_destruct_packet; - vp8->data = NULL; -} - static int vp8_handle_packet(AVFormatContext *ctx, PayloadContext *vp8, AVStream *st, @@ -133,7 +124,9 @@ static int vp8_handle_packet(AVFormatContext *ctx, avio_write(vp8->data, buf, len); if (end_packet) { - prepare_packet(pkt, vp8, st->index); + int ret = ff_rtp_finalize_packet(pkt, &vp8->data, st->index); + if (ret < 0) + return ret; return 0; } diff --git a/libavformat/rtpdec_xiph.c b/libavformat/rtpdec_xiph.c index 38f12bbc39..40415d8f2f 100644 --- a/libavformat/rtpdec_xiph.c +++ b/libavformat/rtpdec_xiph.c @@ -202,20 +202,13 @@ static int xiph_handle_packet(AVFormatContext * ctx, if (fragmented == 3) { // end of xiph data packet - av_init_packet(pkt); - pkt->size = avio_close_dyn_buf(data->fragment, &pkt->data); - - if (pkt->size < 0) { + int ret = ff_rtp_finalize_packet(pkt, &data->fragment, st->index); + if (ret < 0) { av_log(ctx, AV_LOG_ERROR, "Error occurred when getting fragment buffer."); - return pkt->size; + return ret; } - pkt->stream_index = st->index; - pkt->destruct = av_destruct_packet; - - data->fragment = NULL; - return 0; } } -- cgit v1.2.3 From fdc867288697d8b052145e80911d2d338d7d02b7 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 31 Oct 2012 22:10:41 +0100 Subject: audiointerleave: deobfuscate a function call. right above there is if (pkt) {; pkt = NULL}, so pkt is just a fancy name for NULL at this point. --- libavformat/audiointerleave.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libavformat') diff --git a/libavformat/audiointerleave.c b/libavformat/audiointerleave.c index e48f826e14..5df0bb0b40 100644 --- a/libavformat/audiointerleave.c +++ b/libavformat/audiointerleave.c @@ -130,5 +130,5 @@ int ff_audio_rechunk_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt } } - return get_packet(s, out, pkt, flush); + return get_packet(s, out, NULL, flush); } -- cgit v1.2.3 From 2b831a59d9ea82ef5d906a58b11c41f51029b16e Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Tue, 9 Oct 2012 01:17:45 +0300 Subject: rtpdec_vp8: Don't parse fields that aren't used MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This avoids warnings about unused variables. Signed-off-by: Martin Storsjö --- libavformat/rtpdec_vp8.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) (limited to 'libavformat') diff --git a/libavformat/rtpdec_vp8.c b/libavformat/rtpdec_vp8.c index 541a1bcd96..a364358541 100644 --- a/libavformat/rtpdec_vp8.c +++ b/libavformat/rtpdec_vp8.c @@ -45,16 +45,14 @@ static int vp8_handle_packet(AVFormatContext *ctx, int len, int flags) { int start_partition, end_packet; - int extended_bits, non_ref, part_id; + int extended_bits, part_id; int pictureid_present = 0, tl0picidx_present = 0, tid_present = 0, keyidx_present = 0; - int pictureid = -1, keyidx = -1; if (len < 1) return AVERROR_INVALIDDATA; extended_bits = buf[0] & 0x80; - non_ref = buf[0] & 0x20; start_partition = buf[0] & 0x10; part_id = buf[0] & 0x0f; end_packet = flags & RTP_FLAG_MARKER; @@ -71,19 +69,12 @@ static int vp8_handle_packet(AVFormatContext *ctx, len--; } if (pictureid_present) { + int size; if (len < 1) return AVERROR_INVALIDDATA; - if (buf[0] & 0x80) { - if (len < 2) - return AVERROR_INVALIDDATA; - pictureid = AV_RB16(buf) & 0x7fff; - buf += 2; - len -= 2; - } else { - pictureid = buf[0] & 0x7f; - buf++; - len--; - } + size = buf[0] & 0x80 ? 2 : 1; + buf += size; + len -= size; } if (tl0picidx_present) { // Ignoring temporal level zero index @@ -91,11 +82,7 @@ static int vp8_handle_packet(AVFormatContext *ctx, len--; } if (tid_present || keyidx_present) { - // Ignoring temporal layer index and layer sync bit - if (len < 1) - return AVERROR_INVALIDDATA; - if (keyidx_present) - keyidx = buf[0] & 0x1f; + // Ignoring temporal layer index, layer sync bit and keyframe index buf++; len--; } -- cgit v1.2.3