X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fspdifdec.c;h=7c212353f174d9a37547f8350333cbaad840c49a;hb=79fdbfdb3e50f3f906903e027714ee04c1a00e89;hp=05a914531882aacb2e4ec2924a2ca5df292d667c;hpb=d8e481bb860747808220d2baf0cdec5a70c54c1e;p=ffmpeg diff --git a/libavformat/spdifdec.c b/libavformat/spdifdec.c index 05a91453188..7c212353f17 100644 --- a/libavformat/spdifdec.c +++ b/libavformat/spdifdec.c @@ -2,20 +2,20 @@ * IEC 61937 demuxer * Copyright (c) 2010 Anssi Hannula * - * This file is part of FFmpeg. + * This file is part of Libav. * - * FFmpeg is free software; you can redistribute it and/or + * Libav is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * FFmpeg is distributed in the hope that it will be useful, + * Libav is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software + * License along with Libav; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -33,7 +33,7 @@ static int spdif_get_offset_and_codec(AVFormatContext *s, enum IEC61937DataType data_type, const char *buf, int *offset, - enum CodecID *codec) + enum AVCodecID *codec) { AACADTSHeaderInfo aac_hdr; GetBitContext gbc; @@ -41,58 +41,58 @@ static int spdif_get_offset_and_codec(AVFormatContext *s, switch (data_type & 0xff) { case IEC61937_AC3: *offset = AC3_FRAME_SIZE << 2; - *codec = CODEC_ID_AC3; + *codec = AV_CODEC_ID_AC3; break; case IEC61937_MPEG1_LAYER1: *offset = spdif_mpeg_pkt_offset[1][0]; - *codec = CODEC_ID_MP1; + *codec = AV_CODEC_ID_MP1; break; case IEC61937_MPEG1_LAYER23: *offset = spdif_mpeg_pkt_offset[1][0]; - *codec = CODEC_ID_MP3; + *codec = AV_CODEC_ID_MP3; break; case IEC61937_MPEG2_EXT: *offset = 4608; - *codec = CODEC_ID_MP3; + *codec = AV_CODEC_ID_MP3; break; case IEC61937_MPEG2_AAC: init_get_bits(&gbc, buf, AAC_ADTS_HEADER_SIZE * 8); - if (ff_aac_parse_header(&gbc, &aac_hdr)) { + if (avpriv_aac_parse_header(&gbc, &aac_hdr)) { if (s) /* be silent during a probe */ av_log(s, AV_LOG_ERROR, "Invalid AAC packet in IEC 61937\n"); return AVERROR_INVALIDDATA; } *offset = aac_hdr.samples << 2; - *codec = CODEC_ID_AAC; + *codec = AV_CODEC_ID_AAC; break; case IEC61937_MPEG2_LAYER1_LSF: *offset = spdif_mpeg_pkt_offset[0][0]; - *codec = CODEC_ID_MP1; + *codec = AV_CODEC_ID_MP1; break; case IEC61937_MPEG2_LAYER2_LSF: *offset = spdif_mpeg_pkt_offset[0][1]; - *codec = CODEC_ID_MP2; + *codec = AV_CODEC_ID_MP2; break; case IEC61937_MPEG2_LAYER3_LSF: *offset = spdif_mpeg_pkt_offset[0][2]; - *codec = CODEC_ID_MP3; + *codec = AV_CODEC_ID_MP3; break; case IEC61937_DTS1: *offset = 2048; - *codec = CODEC_ID_DTS; + *codec = AV_CODEC_ID_DTS; break; case IEC61937_DTS2: *offset = 4096; - *codec = CODEC_ID_DTS; + *codec = AV_CODEC_ID_DTS; break; case IEC61937_DTS3: *offset = 8192; - *codec = CODEC_ID_DTS; + *codec = AV_CODEC_ID_DTS; break; default: if (s) { /* be silent during a probe */ - av_log(s, AV_LOG_WARNING, "Data type 0x%04x", data_type); - av_log_missing_feature(s, " in IEC 61937 is", 1); + avpriv_request_sample(s, "Data type 0x%04x in IEC 61937", + data_type); } return AVERROR_PATCHWELCOME; } @@ -112,7 +112,7 @@ static int spdif_probe(AVProbeData *p) int sync_codes = 0; int consecutive_codes = 0; int offset; - enum CodecID codec; + enum AVCodecID codec; for (; buf < probe_end; buf++) { state = (state << 8) | *buf; @@ -149,13 +149,13 @@ static int spdif_probe(AVProbeData *p) if (sync_codes >= 6) /* good amount of sync codes but with unexpected offsets */ - return AVPROBE_SCORE_MAX / 2; + return AVPROBE_SCORE_EXTENSION; /* some sync codes were found */ - return AVPROBE_SCORE_MAX / 8; + return AVPROBE_SCORE_EXTENSION / 4; } -static int spdif_read_header(AVFormatContext *s, AVFormatParameters *ap) +static int spdif_read_header(AVFormatContext *s) { s->ctx_flags |= AVFMTCTX_NOHEADER; return 0; @@ -163,32 +163,32 @@ static int spdif_read_header(AVFormatContext *s, AVFormatParameters *ap) static int spdif_read_packet(AVFormatContext *s, AVPacket *pkt) { - ByteIOContext *pb = s->pb; + AVIOContext *pb = s->pb; enum IEC61937DataType data_type; - enum CodecID codec_id; + enum AVCodecID codec_id; uint32_t state = 0; int pkt_size_bits, offset, ret; while (state != (AV_BSWAP16C(SYNCWORD1) << 16 | AV_BSWAP16C(SYNCWORD2))) { - state = (state << 8) | get_byte(pb); - if (url_feof(pb)) + state = (state << 8) | avio_r8(pb); + if (pb->eof_reached) return AVERROR_EOF; } - data_type = get_le16(pb); - pkt_size_bits = get_le16(pb); + data_type = avio_rl16(pb); + pkt_size_bits = avio_rl16(pb); if (pkt_size_bits % 16) - av_log_ask_for_sample(s, "Packet does not end to a 16-bit boundary."); + avpriv_request_sample(s, "Packet not ending at a 16-bit boundary"); ret = av_new_packet(pkt, FFALIGN(pkt_size_bits, 16) >> 3); if (ret) return ret; - pkt->pos = url_ftell(pb) - BURST_HEADER_SIZE; + pkt->pos = avio_tell(pb) - BURST_HEADER_SIZE; - if (get_buffer(pb, pkt->data, pkt->size) < pkt->size) { - av_free_packet(pkt); + if (avio_read(pb, pkt->data, pkt->size) < pkt->size) { + av_packet_unref(pkt); return AVERROR_EOF; } ff_spdif_bswap_buf16((uint16_t *)pkt->data, (uint16_t *)pkt->data, pkt->size >> 1); @@ -196,41 +196,40 @@ static int spdif_read_packet(AVFormatContext *s, AVPacket *pkt) ret = spdif_get_offset_and_codec(s, data_type, pkt->data, &offset, &codec_id); if (ret) { - av_free_packet(pkt); + av_packet_unref(pkt); return ret; } /* skip over the padding to the beginning of the next frame */ - url_fskip(pb, offset - pkt->size - BURST_HEADER_SIZE); + avio_skip(pb, offset - pkt->size - BURST_HEADER_SIZE); if (!s->nb_streams) { /* first packet, create a stream */ - AVStream *st = av_new_stream(s, 0); + AVStream *st = avformat_new_stream(s, NULL); if (!st) { - av_free_packet(pkt); + av_packet_unref(pkt); return AVERROR(ENOMEM); } - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = codec_id; - } else if (codec_id != s->streams[0]->codec->codec_id) { - av_log_missing_feature(s, "codec change in IEC 61937", 0); + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = codec_id; + } else if (codec_id != s->streams[0]->codecpar->codec_id) { + avpriv_report_missing_feature(s, "Codec change in IEC 61937"); return AVERROR_PATCHWELCOME; } - if (!s->bit_rate && s->streams[0]->codec->sample_rate) + if (!s->bit_rate && s->streams[0]->codecpar->sample_rate) /* stream bitrate matches 16-bit stereo PCM bitrate for currently supported codecs */ - s->bit_rate = 2 * 16 * s->streams[0]->codec->sample_rate; + s->bit_rate = 2 * 16 * s->streams[0]->codecpar->sample_rate; return 0; } -AVInputFormat spdif_demuxer = { - "spdif", - NULL_IF_CONFIG_SMALL("IEC 61937 (compressed data in S/PDIF)"), - 0, - spdif_probe, - spdif_read_header, - spdif_read_packet, - .flags = AVFMT_GENERIC_INDEX, +AVInputFormat ff_spdif_demuxer = { + .name = "spdif", + .long_name = NULL_IF_CONFIG_SMALL("IEC 61937 (compressed data in S/PDIF)"), + .read_probe = spdif_probe, + .read_header = spdif_read_header, + .read_packet = spdif_read_packet, + .flags = AVFMT_GENERIC_INDEX, };