~ubuntu-branches/ubuntu/quantal/gst-plugins-bad-multiverse0.10/quantal

« back to all changes in this revision

Viewing changes to sys/vdpau/gstvdpvideosrcpad.c

  • Committer: Bazaar Package Importer
  • Author(s): Onkar Shinde
  • Date: 2010-03-13 22:48:10 UTC
  • mfrom: (1.1.16 upstream)
  • Revision ID: james.westby@ubuntu.com-20100313224810-8l25xl017imj7z4l
Tags: 0.10.18-0ubuntu1
* New upstream bugfix release.
* Relevant upstream fixes
  - 598350 : qtmux with AAC streams (from faac) generate invalid files
  - 607105 : faac doesn't negotiate channel positions correctly
  - 606726 : FAAC bitrate setting has no effect

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * GStreamer
 
3
 * Copyright (C) 2009 Carl-Anton Ingmarsson <ca.ingmarsson@gmail.com>
 
4
 *
 
5
 * This library is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU Library General Public
 
7
 * License as published by the Free Software Foundation; either
 
8
 * version 2 of the License, or (at your option) any later version.
 
9
 *
 
10
 * This library is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * Library General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU Library General Public
 
16
 * License along with this library; if not, write to the
 
17
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
18
 * Boston, MA 02111-1307, USA.
 
19
 */
 
20
 
 
21
#include "gstvdpvideobuffer.h"
 
22
 
 
23
#include "gstvdpvideosrcpad.h"
 
24
 
 
25
GST_DEBUG_CATEGORY_STATIC (gst_vdp_video_src_pad_debug);
 
26
#define GST_CAT_DEFAULT gst_vdp_video_src_pad_debug
 
27
 
 
28
enum
 
29
{
 
30
  PROP_0,
 
31
  PROP_DISPLAY,
 
32
  PROP_TEMPL_CAPS
 
33
};
 
34
 
 
35
#define DEBUG_INIT(bla) \
 
36
GST_DEBUG_CATEGORY_INIT (gst_vdp_video_src_pad_debug, "vdpvideosrcpad", 0, "GstVdpVideoSrcPad");
 
37
 
 
38
G_DEFINE_TYPE_WITH_CODE (GstVdpVideoSrcPad, gst_vdp_video_src_pad, GST_TYPE_PAD,
 
39
    DEBUG_INIT ());
 
40
 
 
41
GstFlowReturn
 
42
gst_vdp_video_src_pad_push (GstVdpVideoSrcPad * vdp_pad,
 
43
    GstVdpVideoBuffer * video_buf)
 
44
{
 
45
  GstPad *pad;
 
46
  GstBuffer *out_buf;
 
47
 
 
48
  g_return_val_if_fail (GST_IS_VDP_VIDEO_SRC_PAD (vdp_pad), GST_FLOW_ERROR);
 
49
  g_return_val_if_fail (GST_IS_VDP_VIDEO_BUFFER (video_buf), GST_FLOW_ERROR);
 
50
 
 
51
  pad = (GstPad *) vdp_pad;
 
52
 
 
53
  if (G_UNLIKELY (!GST_PAD_CAPS (pad)))
 
54
    return GST_FLOW_NOT_NEGOTIATED;
 
55
 
 
56
  if (vdp_pad->yuv_output) {
 
57
    guint size;
 
58
    GstFlowReturn ret;
 
59
    GstCaps *caps;
 
60
 
 
61
    if (!gst_vdp_video_buffer_calculate_size (vdp_pad->fourcc, vdp_pad->width,
 
62
            vdp_pad->height, &size)) {
 
63
      GST_ERROR_OBJECT (vdp_pad, "Couldn't calculate buffer size for caps");
 
64
      gst_buffer_unref (GST_BUFFER_CAST (video_buf));
 
65
      return GST_FLOW_ERROR;
 
66
    }
 
67
 
 
68
    caps = GST_PAD_CAPS (pad);
 
69
    ret = gst_pad_alloc_buffer (pad,
 
70
        GST_BUFFER_OFFSET_NONE, size, caps, &out_buf);
 
71
    if (ret != GST_FLOW_OK) {
 
72
      gst_buffer_unref (GST_BUFFER_CAST (video_buf));
 
73
      return ret;
 
74
    }
 
75
 
 
76
    if (!gst_caps_is_equal_fixed (caps, GST_BUFFER_CAPS (out_buf))) {
 
77
      GST_ERROR_OBJECT (vdp_pad,
 
78
          "Sink element allocated buffer with different caps");
 
79
      gst_buffer_unref (GST_BUFFER_CAST (video_buf));
 
80
      gst_buffer_unref (out_buf);
 
81
      return GST_FLOW_ERROR;
 
82
    }
 
83
 
 
84
    if (!gst_vdp_video_buffer_download (video_buf, out_buf, vdp_pad->fourcc,
 
85
            vdp_pad->width, vdp_pad->height)) {
 
86
      GST_ERROR_OBJECT (vdp_pad,
 
87
          "Couldn't convert from GstVdpVideoBuffer to the requested format");
 
88
      gst_buffer_unref (GST_BUFFER_CAST (video_buf));
 
89
      gst_buffer_unref (out_buf);
 
90
      return GST_FLOW_ERROR;
 
91
    }
 
92
 
 
93
    gst_buffer_copy_metadata (out_buf, (const GstBuffer *) video_buf,
 
94
        GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS);
 
95
    gst_buffer_unref (GST_BUFFER_CAST (video_buf));
 
96
  } else
 
97
    out_buf = GST_BUFFER (video_buf);
 
98
 
 
99
  gst_buffer_set_caps (out_buf, GST_PAD_CAPS (vdp_pad));
 
100
 
 
101
  return gst_pad_push (pad, out_buf);
 
102
}
 
103
 
 
104
static void
 
105
gst_vdp_video_src_pad_update_caps (GstVdpVideoSrcPad * vdp_pad)
 
106
{
 
107
  GstCaps *yuv_caps, *video_caps;
 
108
 
 
109
  video_caps = gst_vdp_video_buffer_get_allowed_video_caps (vdp_pad->device);
 
110
  yuv_caps = gst_vdp_video_buffer_get_allowed_yuv_caps (vdp_pad->device);
 
111
  gst_caps_append (video_caps, yuv_caps);
 
112
 
 
113
 
 
114
  if (vdp_pad->caps)
 
115
    gst_caps_unref (vdp_pad->caps);
 
116
 
 
117
  if (vdp_pad->templ_caps) {
 
118
    vdp_pad->caps = gst_caps_intersect (video_caps, vdp_pad->templ_caps);
 
119
    gst_caps_unref (video_caps);
 
120
  } else
 
121
    vdp_pad->caps = video_caps;
 
122
}
 
123
 
 
124
GstFlowReturn
 
125
gst_vdp_video_src_pad_alloc_buffer (GstVdpVideoSrcPad * vdp_pad,
 
126
    GstVdpVideoBuffer ** video_buf)
 
127
{
 
128
  GstCaps *caps;
 
129
  GstFlowReturn ret;
 
130
 
 
131
  g_return_val_if_fail (GST_IS_VDP_VIDEO_SRC_PAD (vdp_pad), GST_FLOW_ERROR);
 
132
 
 
133
  caps = GST_PAD_CAPS (vdp_pad);
 
134
  if (!caps)
 
135
    return GST_FLOW_NOT_NEGOTIATED;
 
136
 
 
137
  if (vdp_pad->yuv_output) {
 
138
    GstVdpDevice *device;
 
139
 
 
140
    if (G_UNLIKELY (!vdp_pad->device)) {
 
141
      vdp_pad->device = gst_vdp_get_device (vdp_pad->display);
 
142
      if (G_UNLIKELY (!vdp_pad->device))
 
143
        goto device_error;
 
144
 
 
145
      gst_vdp_video_src_pad_update_caps (vdp_pad);
 
146
    }
 
147
    device = vdp_pad->device;
 
148
 
 
149
    *video_buf = gst_vdp_video_buffer_new (device, VDP_CHROMA_TYPE_420,
 
150
        vdp_pad->width, vdp_pad->height);
 
151
    if (!*video_buf)
 
152
      goto video_buffer_error;
 
153
  } else {
 
154
    ret = gst_pad_alloc_buffer ((GstPad *) vdp_pad, 0, 0, caps,
 
155
        (GstBuffer **) video_buf);
 
156
    if (ret != GST_FLOW_OK)
 
157
      return ret;
 
158
 
 
159
    if (!gst_caps_is_equal_fixed (caps, GST_BUFFER_CAPS (*video_buf)))
 
160
      goto wrong_caps;
 
161
 
 
162
    if (G_UNLIKELY (!vdp_pad->device)) {
 
163
      vdp_pad->device =
 
164
          g_object_ref (GST_VDP_VIDEO_BUFFER (*video_buf)->device);
 
165
 
 
166
      gst_vdp_video_src_pad_update_caps (vdp_pad);
 
167
    }
 
168
  }
 
169
 
 
170
  return GST_FLOW_OK;
 
171
 
 
172
device_error:
 
173
  GST_ERROR_OBJECT (vdp_pad, "Couldn't create GstVdpDevice");
 
174
  return GST_FLOW_ERROR;
 
175
 
 
176
video_buffer_error:
 
177
  GST_ERROR_OBJECT (vdp_pad, "Couldn't create GstVdpVideoBuffer");
 
178
  return GST_FLOW_ERROR;
 
179
 
 
180
wrong_caps:
 
181
  GST_ERROR_OBJECT (vdp_pad, "Sink element returned buffer with wrong caps");
 
182
  gst_buffer_unref (GST_BUFFER_CAST (*video_buf));
 
183
  return GST_FLOW_ERROR;
 
184
}
 
185
 
 
186
gboolean
 
187
gst_vdp_video_src_pad_set_caps (GstVdpVideoSrcPad * vdp_pad, GstCaps * caps)
 
188
{
 
189
  const GstStructure *structure;
 
190
 
 
191
  g_return_val_if_fail (GST_IS_VDP_VIDEO_SRC_PAD (vdp_pad), FALSE);
 
192
 
 
193
  if (G_UNLIKELY (!caps))
 
194
    return gst_pad_set_caps (GST_PAD (vdp_pad), caps);
 
195
 
 
196
  if (G_UNLIKELY (!GST_IS_CAPS (caps) || !gst_caps_is_fixed (caps)))
 
197
    return FALSE;
 
198
 
 
199
  structure = gst_caps_get_structure (caps, 0);
 
200
  if (gst_structure_has_name (structure, "video/x-raw-yuv")) {
 
201
    if (!gst_structure_get_int (structure, "width", &vdp_pad->width))
 
202
      return FALSE;
 
203
    if (!gst_structure_get_int (structure, "height", &vdp_pad->height))
 
204
      return FALSE;
 
205
    if (!gst_structure_get_fourcc (structure, "format", &vdp_pad->fourcc))
 
206
      return FALSE;
 
207
 
 
208
    vdp_pad->yuv_output = TRUE;
 
209
  } else if (gst_structure_has_name (structure, "video/x-vdpau-video")) {
 
210
    if (!gst_structure_get_int (structure, "width", &vdp_pad->width))
 
211
      return FALSE;
 
212
    if (!gst_structure_get_int (structure, "height", &vdp_pad->height))
 
213
      return FALSE;
 
214
 
 
215
    vdp_pad->yuv_output = FALSE;
 
216
  } else
 
217
    return FALSE;
 
218
 
 
219
  return gst_pad_set_caps (GST_PAD (vdp_pad), caps);
 
220
}
 
221
 
 
222
GstVdpDevice *
 
223
gst_vdp_video_src_pad_get_device (GstVdpVideoSrcPad * vdp_pad)
 
224
{
 
225
  g_return_val_if_fail (GST_IS_VDP_VIDEO_SRC_PAD (vdp_pad), FALSE);
 
226
 
 
227
  return vdp_pad->device;
 
228
}
 
229
 
 
230
static GstCaps *
 
231
gst_vdp_video_src_pad_getcaps (GstPad * pad)
 
232
{
 
233
  GstVdpVideoSrcPad *vdp_pad = (GstVdpVideoSrcPad *) pad;
 
234
 
 
235
  if (vdp_pad->caps)
 
236
    return gst_caps_ref (vdp_pad->caps);
 
237
  else if (vdp_pad->templ_caps)
 
238
    return gst_caps_ref (vdp_pad->templ_caps);
 
239
 
 
240
  return NULL;
 
241
}
 
242
 
 
243
static gboolean
 
244
gst_vdp_video_src_pad_activate_push (GstPad * pad, gboolean active)
 
245
{
 
246
  GstVdpVideoSrcPad *vdp_pad = GST_VDP_VIDEO_SRC_PAD (pad);
 
247
 
 
248
  if (!active) {
 
249
    if (vdp_pad->device)
 
250
      g_object_unref (vdp_pad->device);
 
251
    vdp_pad->device = NULL;
 
252
 
 
253
    if (vdp_pad->caps)
 
254
      gst_caps_unref (vdp_pad->caps);
 
255
    vdp_pad->caps = NULL;
 
256
  }
 
257
 
 
258
  return TRUE;
 
259
}
 
260
 
 
261
GstVdpVideoSrcPad *
 
262
gst_vdp_video_src_pad_new (GstCaps * templ_caps)
 
263
{
 
264
  return g_object_new (GST_TYPE_VDP_VIDEO_SRC_PAD, "direction", GST_PAD_SRC,
 
265
      "template-caps", templ_caps, NULL);
 
266
}
 
267
 
 
268
static void
 
269
gst_vdp_video_src_pad_get_property (GObject * object, guint prop_id,
 
270
    GValue * value, GParamSpec * pspec)
 
271
{
 
272
  GstVdpVideoSrcPad *vdp_pad = (GstVdpVideoSrcPad *) object;
 
273
 
 
274
  switch (prop_id) {
 
275
    case PROP_DISPLAY:
 
276
      g_value_set_string (value, vdp_pad->display);
 
277
      break;
 
278
    case PROP_TEMPL_CAPS:
 
279
      gst_value_set_caps (value, vdp_pad->templ_caps);
 
280
      break;
 
281
    default:
 
282
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
283
      break;
 
284
  }
 
285
}
 
286
 
 
287
static void
 
288
gst_vdp_video_src_pad_set_property (GObject * object, guint prop_id,
 
289
    const GValue * value, GParamSpec * pspec)
 
290
{
 
291
  GstVdpVideoSrcPad *vdp_pad = (GstVdpVideoSrcPad *) object;
 
292
 
 
293
  switch (prop_id) {
 
294
    case PROP_DISPLAY:
 
295
      vdp_pad->display = g_value_dup_string (value);
 
296
      break;
 
297
    case PROP_TEMPL_CAPS:
 
298
      if (vdp_pad->templ_caps)
 
299
        gst_caps_unref (vdp_pad->templ_caps);
 
300
      vdp_pad->templ_caps = gst_caps_copy (gst_value_get_caps (value));
 
301
      break;
 
302
    default:
 
303
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
304
      break;
 
305
  }
 
306
}
 
307
 
 
308
static void
 
309
gst_vdp_video_src_pad_finalize (GObject * object)
 
310
{
 
311
  GstVdpVideoSrcPad *vdp_pad = (GstVdpVideoSrcPad *) object;
 
312
 
 
313
  g_free (vdp_pad->display);
 
314
  if (vdp_pad->templ_caps)
 
315
    gst_caps_unref (vdp_pad->templ_caps);
 
316
 
 
317
  G_OBJECT_CLASS (gst_vdp_video_src_pad_parent_class)->finalize (object);
 
318
}
 
319
 
 
320
static void
 
321
gst_vdp_video_src_pad_init (GstVdpVideoSrcPad * vdp_pad)
 
322
{
 
323
  GstPad *pad = GST_PAD (vdp_pad);
 
324
 
 
325
  vdp_pad->device = NULL;
 
326
  vdp_pad->caps = NULL;
 
327
 
 
328
  vdp_pad->display = NULL;
 
329
  vdp_pad->templ_caps = NULL;
 
330
 
 
331
  gst_pad_set_getcaps_function (pad,
 
332
      GST_DEBUG_FUNCPTR (gst_vdp_video_src_pad_getcaps));
 
333
  gst_pad_set_activatepush_function (pad,
 
334
      GST_DEBUG_FUNCPTR (gst_vdp_video_src_pad_activate_push));
 
335
}
 
336
 
 
337
static void
 
338
gst_vdp_video_src_pad_class_init (GstVdpVideoSrcPadClass * klass)
 
339
{
 
340
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
341
 
 
342
  object_class->get_property = gst_vdp_video_src_pad_get_property;
 
343
  object_class->set_property = gst_vdp_video_src_pad_set_property;
 
344
  object_class->finalize = gst_vdp_video_src_pad_finalize;
 
345
 
 
346
  g_object_class_install_property (object_class, PROP_DISPLAY,
 
347
      g_param_spec_string ("display", "Display", "X Display name",
 
348
          NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
349
 
 
350
  g_object_class_install_property (object_class, PROP_TEMPL_CAPS,
 
351
      g_param_spec_boxed ("template-caps", "Template caps",
 
352
          "Template caps", GST_TYPE_CAPS,
 
353
          G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
354
 
 
355
}