[FFmpeg-devel] [PATCH] lavc/utils: generalize ff_init_buffer_info() and use it when seems feasible
Stefano Sabatini
stefasab at gmail.com
Thu Aug 2 13:58:57 CEST 2012
Extend ff_init_buffer_info() to init audio frames as well as video
frames.
Avoid code duplication.
---
libavcodec/internal.h | 2 +-
libavcodec/pthread.c | 2 +-
libavcodec/utils.c | 59 ++++++++++++++++--------------------------------
3 files changed, 22 insertions(+), 41 deletions(-)
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 993c42f..3d62a0f 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -122,7 +122,7 @@ unsigned int avpriv_toupper4(unsigned int x);
/**
* does needed setup of pkt_pts/pos and such for (re)get_buffer();
*/
-void ff_init_buffer_info(AVCodecContext *s, AVFrame *pic);
+void ff_init_buffer_info(AVCodecContext *s, AVFrame *pic, enum AVMediaType type);
/**
* Remove and free all side data from packet.
diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c
index 8006ae7..0c505d6 100644
--- a/libavcodec/pthread.c
+++ b/libavcodec/pthread.c
@@ -947,7 +947,7 @@ int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f)
f->owner = avctx;
- ff_init_buffer_info(avctx, f);
+ ff_init_buffer_info(avctx, f, avctx->codec->type);
if (!(avctx->active_thread_type&FF_THREAD_FRAME)) {
f->thread_opaque = NULL;
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 2f4cb5d..71ecf7e 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -289,7 +289,7 @@ void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){
*width=FFALIGN(*width, align);
}
-void ff_init_buffer_info(AVCodecContext *s, AVFrame *pic)
+void ff_init_buffer_info(AVCodecContext *s, AVFrame *pic, enum AVMediaType type)
{
if (s->pkt) {
pic->pkt_pts = s->pkt->pts;
@@ -301,10 +301,21 @@ void ff_init_buffer_info(AVCodecContext *s, AVFrame *pic)
pic->pkt_duration = 0;
}
pic->reordered_opaque= s->reordered_opaque;
- pic->sample_aspect_ratio = s->sample_aspect_ratio;
- pic->width = s->width;
- pic->height = s->height;
- pic->format = s->pix_fmt;
+
+ switch (type) {
+ case AVMEDIA_TYPE_VIDEO:
+ pic->width = s->width;
+ pic->height = s->height;
+ pic->format = s->pix_fmt;
+ pic->sample_aspect_ratio = s->sample_aspect_ratio;
+ break;
+ case AVMEDIA_TYPE_AUDIO:
+ pic->sample_rate = s->sample_rate;
+ pic->format = s->sample_fmt;
+ pic->channel_layout = s->channel_layout;
+ pic->channels = s->channels;
+ break;
+ }
}
int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels,
@@ -411,23 +422,7 @@ static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame)
}
frame->type = FF_BUFFER_TYPE_INTERNAL;
-
- if (avctx->pkt) {
- frame->pkt_pts = avctx->pkt->pts;
- frame->pkt_pos = avctx->pkt->pos;
- frame->pkt_duration = avctx->pkt->duration;
- } else {
- frame->pkt_pts = AV_NOPTS_VALUE;
- frame->pkt_pos = -1;
- frame->pkt_duration = 0;
- }
-
- frame->reordered_opaque = avctx->reordered_opaque;
-
- frame->sample_rate = avctx->sample_rate;
- frame->format = avctx->sample_fmt;
- frame->channel_layout = avctx->channel_layout;
- frame->channels = avctx->channels;
+ ff_init_buffer_info(avctx, frame, AVMEDIA_TYPE_AUDIO);
if (avctx->debug & FF_DEBUG_BUFFERS)
av_log(avctx, AV_LOG_DEBUG, "default_get_buffer called on frame %p, "
@@ -553,22 +548,8 @@ static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
pic->width = buf->width;
pic->height = buf->height;
pic->format = buf->pix_fmt;
- pic->sample_aspect_ratio = s->sample_aspect_ratio;
- if (s->pkt) {
- pic->pkt_pts = s->pkt->pts;
- pic->pkt_pos = s->pkt->pos;
- pic->pkt_duration = s->pkt->duration;
- } else {
- pic->pkt_pts = AV_NOPTS_VALUE;
- pic->pkt_pos = -1;
- pic->pkt_duration = 0;
- }
- pic->reordered_opaque= s->reordered_opaque;
- pic->sample_aspect_ratio = s->sample_aspect_ratio;
- pic->width = s->width;
- pic->height = s->height;
- pic->format = s->pix_fmt;
+ ff_init_buffer_info(s, pic, AVMEDIA_TYPE_VIDEO);
if(s->debug&FF_DEBUG_BUFFERS)
av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p, %d "
@@ -637,7 +618,7 @@ int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){
s->release_buffer(s, pic);
}
- ff_init_buffer_info(s, pic);
+ ff_init_buffer_info(s, pic, s->codec->type);
/* If no picture return a new buffer */
if(pic->data[0] == NULL) {
@@ -2463,7 +2444,7 @@ int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f)
{
f->owner = avctx;
- ff_init_buffer_info(avctx, f);
+ ff_init_buffer_info(avctx, f, avctx->codec->type);
return avctx->get_buffer(avctx, f);
}
--
1.7.5.4
More information about the ffmpeg-devel
mailing list