X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Famr.c;h=e4f8e4d8606a19b044cb749dc4cff09e59fdd6a7;hb=252500a78fe1a31abc79e6070d16f50382c39343;hp=de347058f3fbcaa0ffcba10183803d04e928b34c;hpb=06476249cd2332e30b66576633b2827adf3478dd;p=ffmpeg diff --git a/libavformat/amr.c b/libavformat/amr.c index de347058f3f..e4f8e4d8606 100644 --- a/libavformat/amr.c +++ b/libavformat/amr.c @@ -29,6 +29,7 @@ Only mono files are supported. #include "libavutil/channel_layout.h" #include "avformat.h" #include "internal.h" +#include "rawenc.h" typedef struct { uint64_t cumulated_size; @@ -60,18 +61,11 @@ static int amr_write_header(AVFormatContext *s) } else { return -1; } - avio_flush(pb); - return 0; -} - -static int amr_write_packet(AVFormatContext *s, AVPacket *pkt) -{ - avio_write(s->pb, pkt->data, pkt->size); return 0; } #endif /* CONFIG_AMR_MUXER */ -static int amr_probe(AVProbeData *p) +static int amr_probe(const AVProbeData *p) { // Only check for "#!AMR" which could be amr-wb, amr-nb. // This will also trigger multichannel files: "#!AMR_MC1.0\n" and @@ -90,13 +84,15 @@ static int amr_read_header(AVFormatContext *s) AVStream *st; uint8_t header[9]; - avio_read(pb, header, 6); + if (avio_read(pb, header, 6) != 6) + return AVERROR_INVALIDDATA; st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); if (memcmp(header, AMR_header, 6)) { - avio_read(pb, header + 6, 3); + if (avio_read(pb, header + 6, 3) != 3) + return AVERROR_INVALIDDATA; if (memcmp(header, AMRWB_header, 9)) { return -1; } @@ -154,7 +150,6 @@ static int amr_read_packet(AVFormatContext *s, AVPacket *pkt) read = avio_read(s->pb, pkt->data + 1, size - 1); if (read != size - 1) { - av_packet_unref(pkt); if (read < 0) return read; return AVERROR(EIO); @@ -176,7 +171,7 @@ AVInputFormat ff_amr_demuxer = { #endif #if CONFIG_AMRNB_DEMUXER -static int amrnb_probe(AVProbeData *p) +static int amrnb_probe(const AVProbeData *p) { int mode, i = 0, valid = 0, invalid = 0; const uint8_t *b = p->buf; @@ -232,7 +227,7 @@ AVInputFormat ff_amrnb_demuxer = { #endif #if CONFIG_AMRWB_DEMUXER -static int amrwb_probe(AVProbeData *p) +static int amrwb_probe(const AVProbeData *p) { int mode, i = 0, valid = 0, invalid = 0; const uint8_t *b = p->buf; @@ -296,7 +291,7 @@ AVOutputFormat ff_amr_muxer = { .audio_codec = AV_CODEC_ID_AMR_NB, .video_codec = AV_CODEC_ID_NONE, .write_header = amr_write_header, - .write_packet = amr_write_packet, + .write_packet = ff_raw_write_packet, .flags = AVFMT_NOTIMESTAMPS, }; #endif