X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fdss.c;h=ee3a099a950c417eb0b0eca72da20669b7414415;hb=2606c48391377681541111263de41c79adeffa49;hp=0585049130234d0ac4fbe05387a98f8fbbcffb93;hpb=aebf314ab8ca93c00c2ee055d23d7ba14274a483;p=ffmpeg diff --git a/libavformat/dss.c b/libavformat/dss.c index 05850491302..ee3a099a950 100644 --- a/libavformat/dss.c +++ b/libavformat/dss.c @@ -50,7 +50,6 @@ typedef struct DSSDemuxContext { int counter; int swap; int dss_sp_swap_byte; - int8_t dss_sp_buf[DSS_FRAME_SIZE + 1]; int packet_size; int dss_header_size; @@ -144,6 +143,8 @@ static int dss_read_header(AVFormatContext *s) if (ctx->audio_codec == DSS_ACODEC_DSS_SP) { st->codecpar->codec_id = AV_CODEC_ID_DSS_SP; st->codecpar->sample_rate = 11025; + s->bit_rate = 8 * (DSS_FRAME_SIZE - 1) * st->codecpar->sample_rate + * 512 / (506 * 264); } else if (ctx->audio_codec == DSS_ACODEC_G723_1) { st->codecpar->codec_id = AV_CODEC_ID_G723_1; st->codecpar->sample_rate = 8000; @@ -180,33 +181,29 @@ static void dss_skip_audio_header(AVFormatContext *s, AVPacket *pkt) ctx->counter += DSS_BLOCK_SIZE - DSS_AUDIO_BLOCK_HEADER_SIZE; } -static void dss_sp_byte_swap(DSSDemuxContext *ctx, - uint8_t *dst, const uint8_t *src) +static void dss_sp_byte_swap(DSSDemuxContext *ctx, uint8_t *data) { int i; if (ctx->swap) { - for (i = 3; i < DSS_FRAME_SIZE; i += 2) - dst[i] = src[i]; - for (i = 0; i < DSS_FRAME_SIZE - 2; i += 2) - dst[i] = src[i + 4]; + data[i] = data[i + 4]; - dst[1] = ctx->dss_sp_swap_byte; + /* Zero the padding. */ + data[DSS_FRAME_SIZE] = 0; + data[1] = ctx->dss_sp_swap_byte; } else { - memcpy(dst, src, DSS_FRAME_SIZE); - ctx->dss_sp_swap_byte = src[DSS_FRAME_SIZE - 2]; + ctx->dss_sp_swap_byte = data[DSS_FRAME_SIZE - 2]; } /* make sure byte 40 is always 0 */ - dst[DSS_FRAME_SIZE - 2] = 0; + data[DSS_FRAME_SIZE - 2] = 0; ctx->swap ^= 1; } static int dss_sp_read_packet(AVFormatContext *s, AVPacket *pkt) { DSSDemuxContext *ctx = s->priv_data; - AVStream *st = s->streams[0]; int read_size, ret, offset = 0, buff_offset = 0; int64_t pos = avio_tell(s->pb); @@ -219,9 +216,6 @@ static int dss_sp_read_packet(AVFormatContext *s, AVPacket *pkt) } else read_size = DSS_FRAME_SIZE; - ctx->counter -= read_size; - ctx->packet_size = DSS_FRAME_SIZE - 1; - ret = av_new_packet(pkt, DSS_FRAME_SIZE); if (ret < 0) return ret; @@ -229,32 +223,31 @@ static int dss_sp_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->duration = 264; pkt->pos = pos; pkt->stream_index = 0; - s->bit_rate = 8LL * ctx->packet_size * st->codecpar->sample_rate * 512 / (506 * pkt->duration); - if (ctx->counter < 0) { - int size2 = ctx->counter + read_size; - - ret = avio_read(s->pb, ctx->dss_sp_buf + offset + buff_offset, - size2 - offset); - if (ret < size2 - offset) + if (ctx->counter < read_size) { + ret = avio_read(s->pb, pkt->data + buff_offset, + ctx->counter); + if (ret < ctx->counter) goto error_eof; + offset = ctx->counter; dss_skip_audio_header(s, pkt); - offset = size2; } + ctx->counter -= read_size; - ret = avio_read(s->pb, ctx->dss_sp_buf + offset + buff_offset, + /* This will write one byte into pkt's padding if buff_offset == 3 */ + ret = avio_read(s->pb, pkt->data + offset + buff_offset, read_size - offset); if (ret < read_size - offset) goto error_eof; - dss_sp_byte_swap(ctx, pkt->data, ctx->dss_sp_buf); + dss_sp_byte_swap(ctx, pkt->data); if (ctx->dss_sp_swap_byte < 0) { return AVERROR(EAGAIN); } - return pkt->size; + return 0; error_eof: return ret < 0 ? ret : AVERROR_EOF; @@ -278,7 +271,7 @@ static int dss_723_1_read_packet(AVFormatContext *s, AVPacket *pkt) size = frame_size[byte & 3]; ctx->packet_size = size; - ctx->counter -= size; + ctx->counter--; ret = av_new_packet(pkt, size); if (ret < 0) @@ -288,29 +281,28 @@ static int dss_723_1_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->data[0] = byte; offset = 1; pkt->duration = 240; - s->bit_rate = 8LL * size * st->codecpar->sample_rate * 512 / (506 * pkt->duration); + s->bit_rate = 8LL * size-- * st->codecpar->sample_rate * 512 / (506 * pkt->duration); pkt->stream_index = 0; - if (ctx->counter < 0) { - int size2 = ctx->counter + size; - + if (ctx->counter < size) { ret = avio_read(s->pb, pkt->data + offset, - size2 - offset); - if (ret < size2 - offset) { + ctx->counter); + if (ret < ctx->counter) return ret < 0 ? ret : AVERROR_EOF; - } + offset += ctx->counter; + size -= ctx->counter; + ctx->counter = 0; dss_skip_audio_header(s, pkt); - offset = size2; } + ctx->counter -= size; - ret = avio_read(s->pb, pkt->data + offset, size - offset); - if (ret < size - offset) { + ret = avio_read(s->pb, pkt->data + offset, size); + if (ret < size) return ret < 0 ? ret : AVERROR_EOF; - } - return pkt->size; + return 0; } static int dss_read_packet(AVFormatContext *s, AVPacket *pkt) @@ -362,7 +354,7 @@ static int dss_read_seek(AVFormatContext *s, int stream_index, } -AVInputFormat ff_dss_demuxer = { +const AVInputFormat ff_dss_demuxer = { .name = "dss", .long_name = NULL_IF_CONFIG_SMALL("Digital Speech Standard (DSS)"), .priv_data_size = sizeof(DSSDemuxContext),