~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to ffmpeg/libavfilter/vsrc_buffer.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2012-01-12 22:23:28 UTC
  • mfrom: (0.4.7 sid)
  • mto: This revision was merged to the branch mainline in revision 76.
  • Revision ID: package-import@ubuntu.com-20120112222328-8jqdyodym3p84ygu
Tags: 2:1.0~rc4.dfsg1+svn34540-1
* New upstream snapshot
* upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 */
25
25
 
26
26
#include "avfilter.h"
 
27
#include "buffersrc.h"
27
28
#include "vsrc_buffer.h"
28
29
#include "libavutil/imgutils.h"
29
30
 
30
31
typedef struct {
31
 
    int64_t           pts;
32
 
    AVFrame           frame;
33
 
    int               has_frame;
 
32
    AVFilterBufferRef *buf;
34
33
    int               h, w;
35
34
    enum PixelFormat  pix_fmt;
36
35
    AVRational        time_base;     ///< time_base to set in the output link
37
36
    AVRational        pixel_aspect;
38
37
} BufferSourceContext;
39
38
 
 
39
#define CHECK_PARAM_CHANGE(s, c, width, height, format)\
 
40
    if (c->w != width || c->h != height || c->pix_fmt != format) {\
 
41
        av_log(s, AV_LOG_ERROR, "Changing frame properties on the fly is not supported.\n");\
 
42
        return AVERROR(EINVAL);\
 
43
    }
 
44
 
40
45
int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame,
41
46
                             int64_t pts, AVRational pixel_aspect)
42
47
{
43
48
    BufferSourceContext *c = buffer_filter->priv;
44
49
 
45
 
    if (c->has_frame) {
 
50
    if (c->buf) {
46
51
        av_log(buffer_filter, AV_LOG_ERROR,
47
52
               "Buffering several frames is not supported. "
48
53
               "Please consume all available frames before adding a new one.\n"
50
55
        //return -1;
51
56
    }
52
57
 
53
 
    memcpy(c->frame.data    , frame->data    , sizeof(frame->data));
54
 
    memcpy(c->frame.linesize, frame->linesize, sizeof(frame->linesize));
55
 
    c->frame.interlaced_frame= frame->interlaced_frame;
56
 
    c->frame.top_field_first = frame->top_field_first;
57
 
    c->frame.key_frame = frame->key_frame;
58
 
    c->frame.pict_type = frame->pict_type;
59
 
    c->pts = pts;
60
 
    c->pixel_aspect = pixel_aspect;
61
 
    c->has_frame = 1;
 
58
    CHECK_PARAM_CHANGE(buffer_filter, c, frame->width, frame->height, frame->format);
 
59
 
 
60
    c->buf = avfilter_get_video_buffer(buffer_filter->outputs[0], AV_PERM_WRITE,
 
61
                                       c->w, c->h);
 
62
    av_image_copy(c->buf->data, c->buf->linesize, frame->data, frame->linesize,
 
63
                  c->pix_fmt, c->w, c->h);
 
64
 
 
65
    avfilter_copy_frame_props(c->buf, frame);
 
66
    c->buf->pts                    = pts;
 
67
    c->buf->video->pixel_aspect    = pixel_aspect;
 
68
 
 
69
    return 0;
 
70
}
 
71
 
 
72
int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf)
 
73
{
 
74
    BufferSourceContext *c = s->priv;
 
75
 
 
76
    if (c->buf) {
 
77
        av_log(s, AV_LOG_ERROR,
 
78
               "Buffering several frames is not supported. "
 
79
               "Please consume all available frames before adding a new one.\n"
 
80
            );
 
81
        return AVERROR(EINVAL);
 
82
    }
 
83
 
 
84
    CHECK_PARAM_CHANGE(s, c, buf->video->w, buf->video->h, buf->format);
 
85
 
 
86
    c->buf = buf;
62
87
 
63
88
    return 0;
64
89
}
113
138
static int request_frame(AVFilterLink *link)
114
139
{
115
140
    BufferSourceContext *c = link->src->priv;
116
 
    AVFilterBufferRef *picref;
117
141
 
118
 
    if (!c->has_frame) {
 
142
    if (!c->buf) {
119
143
        av_log(link->src, AV_LOG_ERROR,
120
144
               "request_frame() called with no available frame!\n");
121
145
        //return -1;
122
146
    }
123
147
 
124
 
    /* This picture will be needed unmodified later for decoding the next
125
 
     * frame */
126
 
    picref = avfilter_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE |
127
 
                                       AV_PERM_REUSE2,
128
 
                                       link->w, link->h);
129
 
 
130
 
    av_image_copy(picref->data, picref->linesize,
131
 
                  c->frame.data, c->frame.linesize,
132
 
                  picref->format, link->w, link->h);
133
 
 
134
 
    picref->pts                    = c->pts;
135
 
    picref->video->pixel_aspect    = c->pixel_aspect;
136
 
    picref->video->interlaced      = c->frame.interlaced_frame;
137
 
    picref->video->top_field_first = c->frame.top_field_first;
138
 
    picref->video->key_frame       = c->frame.key_frame;
139
 
    picref->video->pict_type       = c->frame.pict_type;
140
 
    avfilter_start_frame(link, avfilter_ref_buffer(picref, ~0));
 
148
    avfilter_start_frame(link, avfilter_ref_buffer(c->buf, ~0));
141
149
    avfilter_draw_slice(link, 0, link->h, 1);
142
150
    avfilter_end_frame(link);
143
 
    avfilter_unref_buffer(picref);
144
 
 
145
 
    c->has_frame = 0;
 
151
    avfilter_unref_buffer(c->buf);
 
152
    c->buf = NULL;
146
153
 
147
154
    return 0;
148
155
}
150
157
static int poll_frame(AVFilterLink *link)
151
158
{
152
159
    BufferSourceContext *c = link->src->priv;
153
 
    return !!(c->has_frame);
 
160
    return !!c->buf;
154
161
}
155
162
 
156
163
AVFilter avfilter_vsrc_buffer = {