... | ... |
@@ -322,7 +322,8 @@ OBJS-$(CONFIG_QTRLE_ENCODER) += qtrleenc.o |
322 | 322 |
OBJS-$(CONFIG_R10K_DECODER) += r210dec.o |
323 | 323 |
OBJS-$(CONFIG_R210_DECODER) += r210dec.o |
324 | 324 |
OBJS-$(CONFIG_RA_144_DECODER) += ra144dec.o ra144.o celp_filters.o |
325 |
-OBJS-$(CONFIG_RA_144_ENCODER) += ra144enc.o ra144.o celp_filters.o |
|
325 |
+OBJS-$(CONFIG_RA_144_ENCODER) += ra144enc.o ra144.o celp_filters.o \ |
|
326 |
+ audio_frame_queue.o |
|
326 | 327 |
OBJS-$(CONFIG_RA_288_DECODER) += ra288.o celp_math.o celp_filters.o |
327 | 328 |
OBJS-$(CONFIG_RALF_DECODER) += ralf.o |
328 | 329 |
OBJS-$(CONFIG_RAWVIDEO_DECODER) += rawdec.o |
... | ... |
@@ -24,6 +24,7 @@ |
24 | 24 |
|
25 | 25 |
#include <stdint.h> |
26 | 26 |
#include "lpc.h" |
27 |
+#include "audio_frame_queue.h" |
|
27 | 28 |
|
28 | 29 |
#define NBLOCKS 4 ///< number of subblocks within a block |
29 | 30 |
#define BLOCKSIZE 40 ///< subblock size in 16-bit words |
... | ... |
@@ -36,6 +37,7 @@ typedef struct { |
36 | 36 |
AVCodecContext *avctx; |
37 | 37 |
AVFrame frame; |
38 | 38 |
LPCContext lpc_ctx; |
39 |
+ AudioFrameQueue afq; |
|
39 | 40 |
int last_frame; |
40 | 41 |
|
41 | 42 |
unsigned int old_energy; ///< previous frame energy |
... | ... |
@@ -28,6 +28,8 @@ |
28 | 28 |
#include <float.h> |
29 | 29 |
|
30 | 30 |
#include "avcodec.h" |
31 |
+#include "audio_frame_queue.h" |
|
32 |
+#include "internal.h" |
|
31 | 33 |
#include "put_bits.h" |
32 | 34 |
#include "celp_filters.h" |
33 | 35 |
#include "ra144.h" |
... | ... |
@@ -37,7 +39,10 @@ static av_cold int ra144_encode_close(AVCodecContext *avctx) |
37 | 37 |
{ |
38 | 38 |
RA144Context *ractx = avctx->priv_data; |
39 | 39 |
ff_lpc_end(&ractx->lpc_ctx); |
40 |
+ ff_af_queue_close(&ractx->afq); |
|
41 |
+#if FF_API_OLD_ENCODE_AUDIO |
|
40 | 42 |
av_freep(&avctx->coded_frame); |
43 |
+#endif |
|
41 | 44 |
return 0; |
42 | 45 |
} |
43 | 46 |
|
... | ... |
@@ -64,11 +69,15 @@ static av_cold int ra144_encode_init(AVCodecContext * avctx) |
64 | 64 |
if (ret < 0) |
65 | 65 |
goto error; |
66 | 66 |
|
67 |
+ ff_af_queue_init(avctx, &ractx->afq); |
|
68 |
+ |
|
69 |
+#if FF_API_OLD_ENCODE_AUDIO |
|
67 | 70 |
avctx->coded_frame = avcodec_alloc_frame(); |
68 | 71 |
if (!avctx->coded_frame) { |
69 | 72 |
ret = AVERROR(ENOMEM); |
70 | 73 |
goto error; |
71 | 74 |
} |
75 |
+#endif |
|
72 | 76 |
|
73 | 77 |
return 0; |
74 | 78 |
error: |
... | ... |
@@ -429,8 +438,8 @@ static void ra144_encode_subblock(RA144Context *ractx, |
429 | 429 |
} |
430 | 430 |
|
431 | 431 |
|
432 |
-static int ra144_encode_frame(AVCodecContext *avctx, uint8_t *frame, |
|
433 |
- int buf_size, void *data) |
|
432 |
+static int ra144_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, |
|
433 |
+ const AVFrame *frame, int *got_packet_ptr) |
|
434 | 434 |
{ |
435 | 435 |
static const uint8_t sizes[LPC_ORDER] = {64, 32, 32, 16, 16, 8, 8, 8, 8, 4}; |
436 | 436 |
static const uint8_t bit_sizes[LPC_ORDER] = {6, 5, 5, 4, 4, 3, 3, 3, 3, 2}; |
... | ... |
@@ -442,16 +451,16 @@ static int ra144_encode_frame(AVCodecContext *avctx, uint8_t *frame, |
442 | 442 |
int16_t block_coefs[NBLOCKS][LPC_ORDER]; |
443 | 443 |
int lpc_refl[LPC_ORDER]; /**< reflection coefficients of the frame */ |
444 | 444 |
unsigned int refl_rms[NBLOCKS]; /**< RMS of the reflection coefficients */ |
445 |
- const int16_t *samples = data; |
|
445 |
+ const int16_t *samples = frame ? (const int16_t *)frame->data[0] : NULL; |
|
446 | 446 |
int energy = 0; |
447 |
- int i, idx; |
|
447 |
+ int i, idx, ret; |
|
448 | 448 |
|
449 | 449 |
if (ractx->last_frame) |
450 | 450 |
return 0; |
451 | 451 |
|
452 |
- if (buf_size < FRAMESIZE) { |
|
453 |
- av_log(avctx, AV_LOG_ERROR, "output buffer too small\n"); |
|
454 |
- return 0; |
|
452 |
+ if ((ret = ff_alloc_packet(avpkt, FRAMESIZE))) { |
|
453 |
+ av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n"); |
|
454 |
+ return ret; |
|
455 | 455 |
} |
456 | 456 |
|
457 | 457 |
/** |
... | ... |
@@ -465,9 +474,9 @@ static int ra144_encode_frame(AVCodecContext *avctx, uint8_t *frame, |
465 | 465 |
lpc_data[i] = ractx->curr_block[BLOCKSIZE + BLOCKSIZE / 2 + i]; |
466 | 466 |
energy += (lpc_data[i] * lpc_data[i]) >> 4; |
467 | 467 |
} |
468 |
- if (data) { |
|
468 |
+ if (frame) { |
|
469 | 469 |
int j; |
470 |
- for (j = 0; j < avctx->frame_size && i < NBLOCKS * BLOCKSIZE; i++, j++) { |
|
470 |
+ for (j = 0; j < frame->nb_samples && i < NBLOCKS * BLOCKSIZE; i++, j++) { |
|
471 | 471 |
lpc_data[i] = samples[j] >> 2; |
472 | 472 |
energy += (lpc_data[i] * lpc_data[i]) >> 4; |
473 | 473 |
} |
... | ... |
@@ -499,7 +508,7 @@ static int ra144_encode_frame(AVCodecContext *avctx, uint8_t *frame, |
499 | 499 |
memset(lpc_refl, 0, sizeof(lpc_refl)); |
500 | 500 |
} |
501 | 501 |
} |
502 |
- init_put_bits(&pb, frame, buf_size); |
|
502 |
+ init_put_bits(&pb, avpkt->data, avpkt->size); |
|
503 | 503 |
for (i = 0; i < LPC_ORDER; i++) { |
504 | 504 |
idx = quantize(lpc_refl[i], ff_lpc_refl_cb[i], sizes[i]); |
505 | 505 |
put_bits(&pb, bit_sizes[i], idx); |
... | ... |
@@ -525,15 +534,24 @@ static int ra144_encode_frame(AVCodecContext *avctx, uint8_t *frame, |
525 | 525 |
|
526 | 526 |
/* copy input samples to current block for processing in next call */ |
527 | 527 |
i = 0; |
528 |
- if (data) { |
|
529 |
- for (; i < avctx->frame_size; i++) |
|
528 |
+ if (frame) { |
|
529 |
+ for (; i < frame->nb_samples; i++) |
|
530 | 530 |
ractx->curr_block[i] = samples[i] >> 2; |
531 |
+ |
|
532 |
+ if ((ret = ff_af_queue_add(&ractx->afq, frame) < 0)) |
|
533 |
+ return ret; |
|
531 | 534 |
} else |
532 | 535 |
ractx->last_frame = 1; |
533 | 536 |
memset(&ractx->curr_block[i], 0, |
534 | 537 |
(NBLOCKS * BLOCKSIZE - i) * sizeof(*ractx->curr_block)); |
535 | 538 |
|
536 |
- return FRAMESIZE; |
|
539 |
+ /* Get the next frame pts/duration */ |
|
540 |
+ ff_af_queue_remove(&ractx->afq, avctx->frame_size, &avpkt->pts, |
|
541 |
+ &avpkt->duration); |
|
542 |
+ |
|
543 |
+ avpkt->size = FRAMESIZE; |
|
544 |
+ *got_packet_ptr = 1; |
|
545 |
+ return 0; |
|
537 | 546 |
} |
538 | 547 |
|
539 | 548 |
|
... | ... |
@@ -543,7 +561,7 @@ AVCodec ff_ra_144_encoder = { |
543 | 543 |
.id = CODEC_ID_RA_144, |
544 | 544 |
.priv_data_size = sizeof(RA144Context), |
545 | 545 |
.init = ra144_encode_init, |
546 |
- .encode = ra144_encode_frame, |
|
546 |
+ .encode2 = ra144_encode_frame, |
|
547 | 547 |
.close = ra144_encode_close, |
548 | 548 |
.capabilities = CODEC_CAP_DELAY | CODEC_CAP_SMALL_LAST_FRAME, |
549 | 549 |
.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16, |