* Copyright (C) 2009 Justin Ruggles
* Copyright (c) 2009 Xuggle Incorporated
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
int abr; ///< flag to enable ABR
int pkt_frame_count; ///< frame count for the current packet
int lookahead; ///< encoder delay
- int sample_count; ///< total sample count (used for pts)
+ int64_t next_pts; ///< next pts, in sample_rate time base
+ int pkt_sample_count; ///< sample count in the current packet
} LibSpeexEncContext;
static av_cold void print_enc_params(AVCodecContext *avctx,
/* set encoding delay */
speex_encoder_ctl(s->enc_state, SPEEX_GET_LOOKAHEAD, &s->lookahead);
- s->sample_count = -s->lookahead;
+ s->next_pts = -s->lookahead;
/* create header packet bytes from header struct */
/* note: libspeex allocates the memory for header_data, which is freed
{
LibSpeexEncContext *s = avctx->priv_data;
int16_t *samples = data;
- int sample_count = s->sample_count;
if (data) {
/* encode Speex frame */
speex_encode_stereo_int(samples, s->header.frame_size, &s->bits);
speex_encode_int(s->enc_state, samples, &s->bits);
s->pkt_frame_count++;
- s->sample_count += avctx->frame_size;
+ s->pkt_sample_count += avctx->frame_size;
} else {
/* handle end-of-stream */
if (!s->pkt_frame_count)
if (s->pkt_frame_count == s->frames_per_packet) {
s->pkt_frame_count = 0;
avctx->coded_frame->pts =
- av_rescale_q(sample_count, (AVRational){ 1, avctx->sample_rate },
+ av_rescale_q(s->next_pts, (AVRational){ 1, avctx->sample_rate },
avctx->time_base);
+ s->next_pts += s->pkt_sample_count;
+ s->pkt_sample_count = 0;
if (buf_size > speex_bits_nbytes(&s->bits)) {
int ret = speex_bits_write(&s->bits, frame, buf_size);
speex_bits_reset(&s->bits);