static int dss_723_1_read_packet(AVFormatContext *s, AVPacket *pkt) { DSSDemuxContext *ctx = s->priv_data; AVStream *st = s->streams[0]; int size, byte, ret, offset; int64_t pos = avio_tell(s->pb); if (ctx->counter == 0) dss_skip_audio_header(s, pkt); /* We make one byte-step here. Don't forget to add offset. */ byte = avio_r8(s->pb); if (byte == 0xff) return AVERROR_INVALIDDATA; size = frame_size[byte & 3]; ctx->packet_size = size; ctx->counter -= size; ret = av_new_packet(pkt, size); if (ret < 0) return ret; pkt->pos = pos; pkt->data[0] = byte; offset = 1; pkt->duration = 240; s->bit_rate = 8LL * size * st->codec->sample_rate * 512 / (506 * pkt->duration); pkt->stream_index = 0; if (ctx->counter < 0) { int size2 = ctx->counter + size; ret = avio_read(s->pb, pkt->data + offset, size2 - offset); if (ret < size2 - offset) { av_packet_unref(pkt); return ret < 0 ? ret : AVERROR_EOF; } dss_skip_audio_header(s, pkt); offset = size2; } ret = avio_read(s->pb, pkt->data + offset, size - offset); if (ret < size - offset) { av_packet_unref(pkt); return ret < 0 ? ret : AVERROR_EOF; } return pkt->size; }
static int dss_sp_read_packet(AVFormatContext *s, AVPacket *pkt) { DSSDemuxContext *ctx = s->priv_data; int read_size, ret, offset = 0, buff_offset = 0; if (ctx->counter == 0) dss_skip_audio_header(s, pkt); pkt->pos = avio_tell(s->pb); if (ctx->swap) { read_size = DSS_FRAME_SIZE - 2; buff_offset = 3; } else read_size = DSS_FRAME_SIZE; ctx->counter -= read_size; ret = av_new_packet(pkt, DSS_FRAME_SIZE); if (ret < 0) return ret; pkt->duration = 0; pkt->stream_index = 0; 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) goto error_eof; dss_skip_audio_header(s, pkt); offset = size2; } ret = avio_read(s->pb, ctx->dss_sp_buf + 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); if (pkt->data[0] == 0xff) return AVERROR_INVALIDDATA; return pkt->size; error_eof: av_free_packet(pkt); return ret < 0 ? ret : AVERROR_EOF; }
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); if (ctx->counter == 0) dss_skip_audio_header(s, pkt); if (ctx->swap) { read_size = DSS_FRAME_SIZE - 2; buff_offset = 3; } 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; pkt->duration = 264; pkt->pos = pos; pkt->stream_index = 0; s->bit_rate = 8LL * ctx->packet_size * st->codec->sample_rate * 512 / (506 * pkt->duration); if (ctx->counter < 0) { int size2 = ctx->counter + read_size; ret = avio_read(s->pb, (unsigned char *) ctx->dss_sp_buf + offset + buff_offset, size2 - offset); if (ret < size2 - offset) goto error_eof; dss_skip_audio_header(s, pkt); offset = size2; } ret = avio_read(s->pb, (unsigned char *) ctx->dss_sp_buf + offset + buff_offset, read_size - offset); if (ret < read_size - offset) goto error_eof; dss_sp_byte_swap(ctx, (uint8_t *) pkt->data, (uint8_t *) ctx->dss_sp_buf); if (ctx->dss_sp_swap_byte < 0) { ret = AVERROR(EAGAIN); goto error_eof; } if (pkt->data[0] == 0xff) return AVERROR_INVALIDDATA; return pkt->size; error_eof: av_packet_unref(pkt); return ret < 0 ? ret : AVERROR_EOF; }