|
|
|
@ -37,10 +37,10 @@ static av_cold int s302m_encode_init(AVCodecContext *avctx) |
|
|
|
|
{ |
|
|
|
|
S302MEncContext *s = avctx->priv_data; |
|
|
|
|
|
|
|
|
|
if (avctx->channels & 1 || avctx->channels > 8) { |
|
|
|
|
if (avctx->ch_layout.nb_channels & 1 || avctx->ch_layout.nb_channels > 8) { |
|
|
|
|
av_log(avctx, AV_LOG_ERROR, |
|
|
|
|
"Encoding %d channel(s) is not allowed. Only 2, 4, 6 and 8 channels are supported.\n", |
|
|
|
|
avctx->channels); |
|
|
|
|
avctx->ch_layout.nb_channels); |
|
|
|
|
return AVERROR(EINVAL); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -61,7 +61,7 @@ static av_cold int s302m_encode_init(AVCodecContext *avctx) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
avctx->frame_size = 0; |
|
|
|
|
avctx->bit_rate = 48000 * avctx->channels * |
|
|
|
|
avctx->bit_rate = 48000 * avctx->ch_layout.nb_channels * |
|
|
|
|
(avctx->bits_per_raw_sample + 4); |
|
|
|
|
s->framing_index = 0; |
|
|
|
|
|
|
|
|
@ -72,9 +72,9 @@ static int s302m_encode2_frame(AVCodecContext *avctx, AVPacket *avpkt, |
|
|
|
|
const AVFrame *frame, int *got_packet_ptr) |
|
|
|
|
{ |
|
|
|
|
S302MEncContext *s = avctx->priv_data; |
|
|
|
|
const int nb_channels = avctx->ch_layout.nb_channels; |
|
|
|
|
const int buf_size = AES3_HEADER_LEN + |
|
|
|
|
(frame->nb_samples * |
|
|
|
|
avctx->channels * |
|
|
|
|
(frame->nb_samples * nb_channels * |
|
|
|
|
(avctx->bits_per_raw_sample + 4)) / 8; |
|
|
|
|
int ret, c, channels; |
|
|
|
|
uint8_t *o; |
|
|
|
@ -91,7 +91,7 @@ static int s302m_encode2_frame(AVCodecContext *avctx, AVPacket *avpkt, |
|
|
|
|
o = avpkt->data; |
|
|
|
|
init_put_bits(&pb, o, buf_size); |
|
|
|
|
put_bits(&pb, 16, buf_size - AES3_HEADER_LEN); |
|
|
|
|
put_bits(&pb, 2, (avctx->channels - 2) >> 1); // number of channels
|
|
|
|
|
put_bits(&pb, 2, (nb_channels - 2) >> 1); // number of channels
|
|
|
|
|
put_bits(&pb, 8, 0); // channel ID
|
|
|
|
|
put_bits(&pb, 2, (avctx->bits_per_raw_sample - 16) / 4); // bits per samples (0 = 16bit, 1 = 20bit, 2 = 24bit)
|
|
|
|
|
put_bits(&pb, 4, 0); // alignments
|
|
|
|
@ -104,7 +104,7 @@ static int s302m_encode2_frame(AVCodecContext *avctx, AVPacket *avpkt, |
|
|
|
|
for (c = 0; c < frame->nb_samples; c++) { |
|
|
|
|
uint8_t vucf = s->framing_index == 0 ? 0x10: 0; |
|
|
|
|
|
|
|
|
|
for (channels = 0; channels < avctx->channels; channels += 2) { |
|
|
|
|
for (channels = 0; channels < nb_channels; channels += 2) { |
|
|
|
|
o[0] = ff_reverse[(samples[0] & 0x0000FF00) >> 8]; |
|
|
|
|
o[1] = ff_reverse[(samples[0] & 0x00FF0000) >> 16]; |
|
|
|
|
o[2] = ff_reverse[(samples[0] & 0xFF000000) >> 24]; |
|
|
|
@ -126,7 +126,7 @@ static int s302m_encode2_frame(AVCodecContext *avctx, AVPacket *avpkt, |
|
|
|
|
for (c = 0; c < frame->nb_samples; c++) { |
|
|
|
|
uint8_t vucf = s->framing_index == 0 ? 0x80: 0; |
|
|
|
|
|
|
|
|
|
for (channels = 0; channels < avctx->channels; channels += 2) { |
|
|
|
|
for (channels = 0; channels < nb_channels; channels += 2) { |
|
|
|
|
o[0] = ff_reverse[ (samples[0] & 0x000FF000) >> 12]; |
|
|
|
|
o[1] = ff_reverse[ (samples[0] & 0x0FF00000) >> 20]; |
|
|
|
|
o[2] = ff_reverse[((samples[0] & 0xF0000000) >> 28) | vucf]; |
|
|
|
@ -147,7 +147,7 @@ static int s302m_encode2_frame(AVCodecContext *avctx, AVPacket *avpkt, |
|
|
|
|
for (c = 0; c < frame->nb_samples; c++) { |
|
|
|
|
uint8_t vucf = s->framing_index == 0 ? 0x10 : 0; |
|
|
|
|
|
|
|
|
|
for (channels = 0; channels < avctx->channels; channels += 2) { |
|
|
|
|
for (channels = 0; channels < nb_channels; channels += 2) { |
|
|
|
|
o[0] = ff_reverse[ samples[0] & 0xFF]; |
|
|
|
|
o[1] = ff_reverse[(samples[0] & 0xFF00) >> 8]; |
|
|
|
|
o[2] = ff_reverse[(samples[1] & 0x0F) << 4] | vucf; |
|
|
|
|