MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / encode_frame

Function encode_frame

libavcodec/libspeexenc.c:264–307  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

262}
263
264static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
265 const AVFrame *frame, int *got_packet_ptr)
266{
267 LibSpeexEncContext *s = avctx->priv_data;
268 int16_t *samples = frame ? (int16_t *)frame->data[0] : NULL;
269 int ret;
270
271 if (samples) {
272 /* encode Speex frame */
273 if (avctx->ch_layout.nb_channels == 2)
274 speex_encode_stereo_int(samples, s->header.frame_size, &s->bits);
275 speex_encode_int(s->enc_state, samples, &s->bits);
276 s->pkt_frame_count++;
277 if ((ret = ff_af_queue_add(&s->afq, frame)) < 0)
278 return ret;
279 } else {
280 /* handle end-of-stream */
281 if (!s->pkt_frame_count)
282 return 0;
283 /* add extra terminator codes for unused frames in last packet */
284 while (s->pkt_frame_count < s->frames_per_packet) {
285 speex_bits_pack(&s->bits, 15, 5);
286 s->pkt_frame_count++;
287 }
288 }
289
290 /* write output if all frames for the packet have been encoded */
291 if (s->pkt_frame_count == s->frames_per_packet) {
292 s->pkt_frame_count = 0;
293 if ((ret = ff_alloc_packet(avctx, avpkt, speex_bits_nbytes(&s->bits))) < 0)
294 return ret;
295 ret = speex_bits_write(&s->bits, avpkt->data, avpkt->size);
296 speex_bits_reset(&s->bits);
297
298 /* Get the next frame pts/duration */
299 ff_af_queue_remove(&s->afq, s->frames_per_packet * avctx->frame_size,
300 &avpkt->pts, &avpkt->duration);
301
302 avpkt->size = ret;
303 *got_packet_ptr = 1;
304 return 0;
305 }
306 return 0;
307}
308
309static av_cold int encode_close(AVCodecContext *avctx)
310{

Callers

nothing calls this directly

Calls 3

ff_af_queue_addFunction · 0.85
ff_alloc_packetFunction · 0.85
ff_af_queue_removeFunction · 0.85

Tested by

no test coverage detected