annotate ffmpeg/libavfilter/avcodec.c @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents 6840f77b83aa
children
rev   line source
yading@10 1 /*
yading@10 2 * Copyright 2011 Stefano Sabatini | stefasab at gmail.com
yading@10 3 *
yading@10 4 * This file is part of FFmpeg.
yading@10 5 *
yading@10 6 * FFmpeg is free software; you can redistribute it and/or
yading@10 7 * modify it under the terms of the GNU Lesser General Public
yading@10 8 * License as published by the Free Software Foundation; either
yading@10 9 * version 2.1 of the License, or (at your option) any later version.
yading@10 10 *
yading@10 11 * FFmpeg is distributed in the hope that it will be useful,
yading@10 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@10 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@10 14 * Lesser General Public License for more details.
yading@10 15 *
yading@10 16 * You should have received a copy of the GNU Lesser General Public
yading@10 17 * License along with FFmpeg; if not, write to the Free Software
yading@10 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@10 19 */
yading@10 20
yading@10 21 /**
yading@10 22 * @file
yading@10 23 * libavcodec/libavfilter gluing utilities
yading@10 24 */
yading@10 25
yading@10 26 #include "avcodec.h"
yading@10 27 #include "libavutil/avassert.h"
yading@10 28 #include "libavutil/channel_layout.h"
yading@10 29 #include "libavutil/opt.h"
yading@10 30
yading@10 31 #if FF_API_AVFILTERBUFFER
yading@10 32 AVFilterBufferRef *avfilter_get_video_buffer_ref_from_frame(const AVFrame *frame,
yading@10 33 int perms)
yading@10 34 {
yading@10 35 AVFilterBufferRef *picref =
yading@10 36 avfilter_get_video_buffer_ref_from_arrays(frame->data, frame->linesize, perms,
yading@10 37 frame->width, frame->height,
yading@10 38 frame->format);
yading@10 39 if (!picref)
yading@10 40 return NULL;
yading@10 41 if (avfilter_copy_frame_props(picref, frame) < 0) {
yading@10 42 picref->buf->data[0] = NULL;
yading@10 43 avfilter_unref_bufferp(&picref);
yading@10 44 }
yading@10 45 return picref;
yading@10 46 }
yading@10 47
yading@10 48 AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_frame(const AVFrame *frame,
yading@10 49 int perms)
yading@10 50 {
yading@10 51 AVFilterBufferRef *samplesref;
yading@10 52 int channels = av_frame_get_channels(frame);
yading@10 53 int64_t layout = av_frame_get_channel_layout(frame);
yading@10 54
yading@10 55 if (layout && av_get_channel_layout_nb_channels(layout) != av_frame_get_channels(frame)) {
yading@10 56 av_log(0, AV_LOG_ERROR, "Layout indicates a different number of channels than actually present\n");
yading@10 57 return NULL;
yading@10 58 }
yading@10 59
yading@10 60 samplesref = avfilter_get_audio_buffer_ref_from_arrays_channels(
yading@10 61 (uint8_t **)frame->extended_data, frame->linesize[0], perms,
yading@10 62 frame->nb_samples, frame->format, channels, layout);
yading@10 63 if (!samplesref)
yading@10 64 return NULL;
yading@10 65 if (avfilter_copy_frame_props(samplesref, frame) < 0) {
yading@10 66 samplesref->buf->data[0] = NULL;
yading@10 67 avfilter_unref_bufferp(&samplesref);
yading@10 68 }
yading@10 69 return samplesref;
yading@10 70 }
yading@10 71
yading@10 72 AVFilterBufferRef *avfilter_get_buffer_ref_from_frame(enum AVMediaType type,
yading@10 73 const AVFrame *frame,
yading@10 74 int perms)
yading@10 75 {
yading@10 76 switch (type) {
yading@10 77 case AVMEDIA_TYPE_VIDEO:
yading@10 78 return avfilter_get_video_buffer_ref_from_frame(frame, perms);
yading@10 79 case AVMEDIA_TYPE_AUDIO:
yading@10 80 return avfilter_get_audio_buffer_ref_from_frame(frame, perms);
yading@10 81 default:
yading@10 82 return NULL;
yading@10 83 }
yading@10 84 }
yading@10 85
yading@10 86 int avfilter_copy_buf_props(AVFrame *dst, const AVFilterBufferRef *src)
yading@10 87 {
yading@10 88 int planes, nb_channels;
yading@10 89
yading@10 90 if (!dst)
yading@10 91 return AVERROR(EINVAL);
yading@10 92 /* abort in case the src is NULL and dst is not, avoid inconsistent state in dst */
yading@10 93 av_assert0(src);
yading@10 94
yading@10 95 memcpy(dst->data, src->data, sizeof(dst->data));
yading@10 96 memcpy(dst->linesize, src->linesize, sizeof(dst->linesize));
yading@10 97
yading@10 98 dst->pts = src->pts;
yading@10 99 dst->format = src->format;
yading@10 100 av_frame_set_pkt_pos(dst, src->pos);
yading@10 101
yading@10 102 switch (src->type) {
yading@10 103 case AVMEDIA_TYPE_VIDEO:
yading@10 104 av_assert0(src->video);
yading@10 105 dst->width = src->video->w;
yading@10 106 dst->height = src->video->h;
yading@10 107 dst->sample_aspect_ratio = src->video->sample_aspect_ratio;
yading@10 108 dst->interlaced_frame = src->video->interlaced;
yading@10 109 dst->top_field_first = src->video->top_field_first;
yading@10 110 dst->key_frame = src->video->key_frame;
yading@10 111 dst->pict_type = src->video->pict_type;
yading@10 112 break;
yading@10 113 case AVMEDIA_TYPE_AUDIO:
yading@10 114 av_assert0(src->audio);
yading@10 115 nb_channels = av_get_channel_layout_nb_channels(src->audio->channel_layout);
yading@10 116 planes = av_sample_fmt_is_planar(src->format) ? nb_channels : 1;
yading@10 117
yading@10 118 if (planes > FF_ARRAY_ELEMS(dst->data)) {
yading@10 119 dst->extended_data = av_mallocz(planes * sizeof(*dst->extended_data));
yading@10 120 if (!dst->extended_data)
yading@10 121 return AVERROR(ENOMEM);
yading@10 122 memcpy(dst->extended_data, src->extended_data,
yading@10 123 planes * sizeof(*dst->extended_data));
yading@10 124 } else
yading@10 125 dst->extended_data = dst->data;
yading@10 126 dst->nb_samples = src->audio->nb_samples;
yading@10 127 av_frame_set_sample_rate (dst, src->audio->sample_rate);
yading@10 128 av_frame_set_channel_layout(dst, src->audio->channel_layout);
yading@10 129 av_frame_set_channels (dst, src->audio->channels);
yading@10 130 break;
yading@10 131 default:
yading@10 132 return AVERROR(EINVAL);
yading@10 133 }
yading@10 134
yading@10 135 return 0;
yading@10 136 }
yading@10 137 #endif
yading@10 138
yading@10 139 #if FF_API_FILL_FRAME
yading@10 140 int avfilter_fill_frame_from_audio_buffer_ref(AVFrame *frame,
yading@10 141 const AVFilterBufferRef *samplesref)
yading@10 142 {
yading@10 143 return avfilter_copy_buf_props(frame, samplesref);
yading@10 144 }
yading@10 145
yading@10 146 int avfilter_fill_frame_from_video_buffer_ref(AVFrame *frame,
yading@10 147 const AVFilterBufferRef *picref)
yading@10 148 {
yading@10 149 return avfilter_copy_buf_props(frame, picref);
yading@10 150 }
yading@10 151
yading@10 152 int avfilter_fill_frame_from_buffer_ref(AVFrame *frame,
yading@10 153 const AVFilterBufferRef *ref)
yading@10 154 {
yading@10 155 return avfilter_copy_buf_props(frame, ref);
yading@10 156 }
yading@10 157 #endif