1 /* GStreamer
2 * Copyright (C) 2008-2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 /* Implementation of SMPTE 384M - Mapping of Uncompressed Pictures into the MXF
21 * Generic Container
22 */
23
24 /* TODO:
25 * - Handle CDCI essence
26 * - Handle more formats with RGBA descriptor (4:4:4 / 4:4:4:4 YUV, RGB656, ...)
27 * - Handle all the dimensions and other properties in the picture
28 * essence descriptors correctly according to S377M Annex E
29 * - Handle interlaced correctly, i.e. weave until we support one-field-per-buffer
30 */
31
32 #ifdef HAVE_CONFIG_H
33 #include "config.h"
34 #endif
35
36 #include <gst/gst.h>
37 #include <string.h>
38
39 #include <gst/video/video.h>
40
41 #include "mxfup.h"
42 #include "mxfessence.h"
43
44 GST_DEBUG_CATEGORY_EXTERN (mxf_debug);
45 #define GST_CAT_DEFAULT mxf_debug
46
47 static const struct
48 {
49 const gchar *format;
50 guint32 n_pixel_layout;
51 guint8 pixel_layout[10];
52 const gchar *caps_string;
53 } _rgba_mapping_table[] = {
54 {
55 "RGB", 3, {
56 'R', 8, 'G', 8, 'B', 8}, GST_VIDEO_CAPS_MAKE ("RGB")}, {
57 "BGR", 3, {
58 'B', 8, 'G', 8, 'R', 8}, GST_VIDEO_CAPS_MAKE ("BGR")}, {
59 "v308", 3, {
60 'Y', 8, 'U', 8, 'V', 8}, GST_VIDEO_CAPS_MAKE ("v308")}, {
61 "xRGB", 4, {
62 'F', 8, 'R', 8, 'G', 8, 'B', 8}, GST_VIDEO_CAPS_MAKE ("xRGB")}, {
63 "RGBx", 4, {
64 'R', 8, 'G', 8, 'B', 8, 'F', 8}, GST_VIDEO_CAPS_MAKE ("RGBx")}, {
65 "xBGR", 4, {
66 'F', 8, 'B', 8, 'G', 8, 'R', 8}, GST_VIDEO_CAPS_MAKE ("xBGR")}, {
67 "BGRx", 4, {
68 'B', 8, 'G', 8, 'R', 8, 'F', 8}, GST_VIDEO_CAPS_MAKE ("BGRx")}, {
69 "RGBA", 4, {
70 'R', 8, 'G', 8, 'B', 8, 'A', 8}, GST_VIDEO_CAPS_MAKE ("RGBA")}, {
71 "ARGB", 4, {
72 'A', 8, 'R', 8, 'G', 8, 'B', 8}, GST_VIDEO_CAPS_MAKE ("RGBA")}, {
73 "BGRA", 4, {
74 'B', 8, 'G', 8, 'R', 8, 'A', 8}, GST_VIDEO_CAPS_MAKE ("BGRA")}, {
75 "ABGR", 4, {
76 'A', 8, 'B', 8, 'G', 8, 'R', 8}, GST_VIDEO_CAPS_MAKE ("ABGR")}, {
77 "AYUV", 4, {
78 'A', 8, 'Y', 8, 'U', 8, 'V', 8}, GST_VIDEO_CAPS_MAKE ("AYUV")}
79 };
80
81 static const struct
82 {
83 const gchar *format;
84 guint bpp;
85 guint horizontal_subsampling;
86 guint vertical_subsampling;
87 gboolean reversed_byte_order;
88 const gchar *caps_string;
89 } _cdci_mapping_table[] = {
90 {
91 "YUY2", 2, 1, 0, TRUE, GST_VIDEO_CAPS_MAKE ("YUY2")}, {
92 "UYVY", 2, 1, 0, FALSE, GST_VIDEO_CAPS_MAKE ("UYVY")},};
93
94 typedef struct
95 {
96 const gchar *format; /* video format string */
97 gint width, height;
98 guint bpp;
99 guint32 image_start_offset;
100 guint32 image_end_offset;
101 } MXFUPMappingData;
102
103 static gboolean
mxf_is_up_essence_track(const MXFMetadataTimelineTrack * track)104 mxf_is_up_essence_track (const MXFMetadataTimelineTrack * track)
105 {
106 guint i;
107
108 g_return_val_if_fail (track != NULL, FALSE);
109
110 if (track->parent.descriptor == NULL)
111 return FALSE;
112
113 for (i = 0; i < track->parent.n_descriptor; i++) {
114 MXFMetadataFileDescriptor *d = track->parent.descriptor[i];
115 MXFUL *key;
116
117 if (!d)
118 continue;
119
120 key = &d->essence_container;
121 /* SMPTE 384M 8 */
122 if (mxf_is_generic_container_essence_container_label (key) &&
123 key->u[12] == 0x02 && key->u[13] == 0x05 && key->u[15] <= 0x03)
124 return TRUE;
125 }
126
127 return FALSE;
128 }
129
130 static GstFlowReturn
mxf_up_handle_essence_element(const MXFUL * key,GstBuffer * buffer,GstCaps * caps,MXFMetadataTimelineTrack * track,gpointer mapping_data,GstBuffer ** outbuf)131 mxf_up_handle_essence_element (const MXFUL * key, GstBuffer * buffer,
132 GstCaps * caps,
133 MXFMetadataTimelineTrack * track,
134 gpointer mapping_data, GstBuffer ** outbuf)
135 {
136 MXFUPMappingData *data = mapping_data;
137
138 /* SMPTE 384M 7.1 */
139 if (key->u[12] != 0x15 || (key->u[14] != 0x01 && key->u[14] != 0x02
140 && key->u[14] != 0x03 && key->u[14] != 0x04)) {
141 GST_ERROR ("Invalid uncompressed picture essence element");
142 gst_buffer_unref (buffer);
143 return GST_FLOW_ERROR;
144 }
145
146 if (!data) {
147 GST_ERROR ("Invalid mapping data");
148 gst_buffer_unref (buffer);
149 return GST_FLOW_ERROR;
150 }
151
152 if (data->image_start_offset == 0 && data->image_end_offset == 0) {
153 } else {
154 if (data->image_start_offset + data->image_end_offset
155 > gst_buffer_get_size (buffer)) {
156 gst_buffer_unref (buffer);
157 GST_ERROR ("Invalid buffer size");
158 return GST_FLOW_ERROR;
159 } else {
160 gst_buffer_resize (buffer, data->image_start_offset,
161 data->image_end_offset - data->image_start_offset);
162 }
163 }
164
165 if (gst_buffer_get_size (buffer) != data->bpp * data->width * data->height) {
166 GST_ERROR ("Invalid buffer size");
167 gst_buffer_unref (buffer);
168 return GST_FLOW_ERROR;
169 }
170
171 if (data->bpp != 4
172 || GST_ROUND_UP_4 (data->width * data->bpp) != data->width * data->bpp) {
173 guint y;
174 GstBuffer *ret;
175 GstMapInfo inmap, outmap;
176 guint8 *indata, *outdata;
177
178 ret =
179 gst_buffer_new_and_alloc (GST_ROUND_UP_4 (data->width * data->bpp) *
180 data->height);
181 gst_buffer_map (buffer, &inmap, GST_MAP_READ);
182 gst_buffer_map (ret, &outmap, GST_MAP_WRITE);
183 indata = inmap.data;
184 outdata = outmap.data;
185
186 for (y = 0; y < data->height; y++) {
187 memcpy (outdata, indata, data->width * data->bpp);
188 outdata += GST_ROUND_UP_4 (data->width * data->bpp);
189 indata += data->width * data->bpp;
190 }
191
192 gst_buffer_unmap (buffer, &inmap);
193 gst_buffer_unmap (ret, &outmap);
194
195 gst_buffer_unref (buffer);
196 *outbuf = ret;
197 } else {
198 *outbuf = buffer;
199 }
200
201 return GST_FLOW_OK;
202 }
203
204 static MXFEssenceWrapping
mxf_up_get_track_wrapping(const MXFMetadataTimelineTrack * track)205 mxf_up_get_track_wrapping (const MXFMetadataTimelineTrack * track)
206 {
207 guint i;
208
209 g_return_val_if_fail (track != NULL, MXF_ESSENCE_WRAPPING_CUSTOM_WRAPPING);
210
211 if (track->parent.descriptor == NULL) {
212 GST_ERROR ("No descriptor found for this track");
213 return MXF_ESSENCE_WRAPPING_CUSTOM_WRAPPING;
214 }
215
216 for (i = 0; i < track->parent.n_descriptor; i++) {
217 if (!track->parent.descriptor[i])
218 continue;
219
220 if (!MXF_IS_METADATA_GENERIC_PICTURE_ESSENCE_DESCRIPTOR (track->
221 parent.descriptor[i]))
222 continue;
223
224 switch (track->parent.descriptor[i]->essence_container.u[15]) {
225 case 0x01:
226 return MXF_ESSENCE_WRAPPING_FRAME_WRAPPING;
227 break;
228 case 0x02:
229 return MXF_ESSENCE_WRAPPING_CLIP_WRAPPING;
230 break;
231 default:
232 return MXF_ESSENCE_WRAPPING_CUSTOM_WRAPPING;
233 break;
234 }
235 }
236
237 return MXF_ESSENCE_WRAPPING_CUSTOM_WRAPPING;
238 }
239
240 static GstCaps *
mxf_up_rgba_create_caps(MXFMetadataTimelineTrack * track,MXFMetadataRGBAPictureEssenceDescriptor * d,GstTagList ** tags,gboolean * intra_only,MXFEssenceElementHandleFunc * handler,gpointer * mapping_data)241 mxf_up_rgba_create_caps (MXFMetadataTimelineTrack * track,
242 MXFMetadataRGBAPictureEssenceDescriptor * d, GstTagList ** tags,
243 gboolean * intra_only, MXFEssenceElementHandleFunc * handler,
244 gpointer * mapping_data)
245 {
246 GstCaps *caps = NULL;
247 guint i;
248 const gchar *format = NULL;
249 guint bpp;
250
251 if (!d->pixel_layout) {
252 GST_ERROR ("No pixel layout");
253 return NULL;
254 }
255
256 for (i = 0; i < G_N_ELEMENTS (_rgba_mapping_table); i++) {
257 if (d->n_pixel_layout != _rgba_mapping_table[i].n_pixel_layout)
258 continue;
259
260 if (memcmp (d->pixel_layout, &_rgba_mapping_table[i].pixel_layout,
261 _rgba_mapping_table[i].n_pixel_layout * 2) == 0) {
262 caps = gst_caps_from_string (_rgba_mapping_table[i].caps_string);
263 format = _rgba_mapping_table[i].format;
264 bpp = _rgba_mapping_table[i].n_pixel_layout;
265 break;
266 }
267 }
268
269 if (caps) {
270 MXFUPMappingData *data = g_new0 (MXFUPMappingData, 1);
271
272 mxf_metadata_generic_picture_essence_descriptor_set_caps (&d->parent, caps);
273
274 data->width = d->parent.stored_width;
275 data->height = d->parent.stored_height;
276 data->format = format;
277 data->bpp = bpp;
278 data->image_start_offset =
279 ((MXFMetadataGenericPictureEssenceDescriptor *) d)->image_start_offset;
280 data->image_end_offset =
281 ((MXFMetadataGenericPictureEssenceDescriptor *) d)->image_end_offset;
282
283 *mapping_data = data;
284 *intra_only = TRUE;
285 } else {
286 GST_WARNING ("Unsupported pixel layout");
287 }
288
289 return caps;
290 }
291
292 static GstCaps *
mxf_up_cdci_create_caps(MXFMetadataTimelineTrack * track,MXFMetadataCDCIPictureEssenceDescriptor * d,GstTagList ** tags,gboolean * intra_only,MXFEssenceElementHandleFunc * handler,gpointer * mapping_data)293 mxf_up_cdci_create_caps (MXFMetadataTimelineTrack * track,
294 MXFMetadataCDCIPictureEssenceDescriptor * d, GstTagList ** tags,
295 gboolean * intra_only, MXFEssenceElementHandleFunc * handler,
296 gpointer * mapping_data)
297 {
298 GstCaps *caps = NULL;
299 guint i;
300 const gchar *format;
301 guint bpp;
302
303 for (i = 0; i < G_N_ELEMENTS (_cdci_mapping_table); i++) {
304 if (_cdci_mapping_table[i].horizontal_subsampling ==
305 d->horizontal_subsampling
306 && _cdci_mapping_table[i].vertical_subsampling ==
307 d->vertical_subsampling
308 && _cdci_mapping_table[i].reversed_byte_order ==
309 d->reversed_byte_order) {
310 caps = gst_caps_from_string (_cdci_mapping_table[i].caps_string);
311 format = _cdci_mapping_table[i].format;
312 bpp = _cdci_mapping_table[i].bpp;
313 break;
314 }
315 }
316
317 if (caps) {
318 MXFUPMappingData *data = g_new0 (MXFUPMappingData, 1);
319
320 mxf_metadata_generic_picture_essence_descriptor_set_caps (&d->parent, caps);
321
322 data->width = d->parent.stored_width;
323 data->height = d->parent.stored_height;
324 data->format = format;
325 data->bpp = bpp;
326 data->image_start_offset =
327 ((MXFMetadataGenericPictureEssenceDescriptor *) d)->image_start_offset;
328 data->image_end_offset =
329 ((MXFMetadataGenericPictureEssenceDescriptor *) d)->image_end_offset;
330
331 *mapping_data = data;
332 *intra_only = TRUE;
333 } else {
334 GST_WARNING ("Unsupported CDCI format");
335 }
336
337 return caps;
338 }
339
340 static GstCaps *
mxf_up_create_caps(MXFMetadataTimelineTrack * track,GstTagList ** tags,gboolean * intra_only,MXFEssenceElementHandleFunc * handler,gpointer * mapping_data)341 mxf_up_create_caps (MXFMetadataTimelineTrack * track, GstTagList ** tags,
342 gboolean * intra_only, MXFEssenceElementHandleFunc * handler,
343 gpointer * mapping_data)
344 {
345 MXFMetadataGenericPictureEssenceDescriptor *p = NULL;
346 MXFMetadataCDCIPictureEssenceDescriptor *c = NULL;
347 MXFMetadataRGBAPictureEssenceDescriptor *r = NULL;
348 guint i;
349 GstCaps *caps = NULL;
350
351 g_return_val_if_fail (track != NULL, NULL);
352
353 if (track->parent.descriptor == NULL) {
354 GST_ERROR ("No descriptor found for this track");
355 return NULL;
356 }
357
358 for (i = 0; i < track->parent.n_descriptor; i++) {
359 if (!track->parent.descriptor[i])
360 continue;
361
362 if (MXF_IS_METADATA_RGBA_PICTURE_ESSENCE_DESCRIPTOR (track->parent.
363 descriptor[i])) {
364 p = (MXFMetadataGenericPictureEssenceDescriptor *) track->parent.
365 descriptor[i];
366 r = (MXFMetadataRGBAPictureEssenceDescriptor *) track->parent.
367 descriptor[i];
368 break;
369 } else if (MXF_IS_METADATA_CDCI_PICTURE_ESSENCE_DESCRIPTOR (track->
370 parent.descriptor[i])) {
371 p = (MXFMetadataGenericPictureEssenceDescriptor *) track->parent.
372 descriptor[i];
373 c = (MXFMetadataCDCIPictureEssenceDescriptor *) track->parent.
374 descriptor[i];
375 }
376 }
377
378 if (!p) {
379 GST_ERROR ("No picture essence descriptor found for this track");
380 return NULL;
381 }
382
383 *handler = mxf_up_handle_essence_element;
384
385 if (r) {
386 caps =
387 mxf_up_rgba_create_caps (track, r, tags, intra_only, handler,
388 mapping_data);
389 } else if (c) {
390 caps =
391 mxf_up_cdci_create_caps (track, c, tags, intra_only, handler,
392 mapping_data);
393 } else {
394 return NULL;
395 }
396
397 return caps;
398 }
399
400 static const MXFEssenceElementHandler mxf_up_essence_element_handler = {
401 mxf_is_up_essence_track,
402 mxf_up_get_track_wrapping,
403 mxf_up_create_caps
404 };
405
406 static GstFlowReturn
mxf_up_write_func(GstBuffer * buffer,gpointer mapping_data,GstAdapter * adapter,GstBuffer ** outbuf,gboolean flush)407 mxf_up_write_func (GstBuffer * buffer, gpointer mapping_data,
408 GstAdapter * adapter, GstBuffer ** outbuf, gboolean flush)
409 {
410 MXFUPMappingData *data = mapping_data;
411
412 if (!buffer)
413 return GST_FLOW_OK;
414
415 if (gst_buffer_get_size (buffer) !=
416 GST_ROUND_UP_4 (data->bpp * data->width) * data->height) {
417 GST_ERROR ("Invalid buffer size");
418 return GST_FLOW_ERROR;
419 }
420
421 if (data->bpp != 4
422 || GST_ROUND_UP_4 (data->width * data->bpp) != data->width * data->bpp) {
423 guint y;
424 GstBuffer *ret;
425 GstMapInfo inmap, outmap;
426 guint8 *indata, *outdata;
427
428 ret = gst_buffer_new_and_alloc (data->width * data->bpp * data->height);
429 gst_buffer_map (buffer, &inmap, GST_MAP_READ);
430 gst_buffer_map (ret, &outmap, GST_MAP_WRITE);
431 indata = inmap.data;
432 outdata = outmap.data;
433
434 for (y = 0; y < data->height; y++) {
435 memcpy (outdata, indata, data->width * data->bpp);
436 indata += GST_ROUND_UP_4 (data->width * data->bpp);
437 outdata += data->width * data->bpp;
438 }
439
440 gst_buffer_unmap (buffer, &inmap);
441 gst_buffer_unmap (ret, &outmap);
442 gst_buffer_unref (buffer);
443
444 *outbuf = ret;
445 } else {
446 *outbuf = buffer;
447 }
448
449 return GST_FLOW_OK;
450 }
451
452 static const guint8 up_essence_container_ul[] = {
453 0x06, 0x0e, 0x2b, 0x34, 0x04, 0x01, 0x01, 0x01,
454 0x0D, 0x01, 0x03, 0x01, 0x02, 0x05, 0x7F, 0x01
455 };
456
457 static MXFMetadataFileDescriptor *
mxf_up_get_rgba_descriptor(GstPadTemplate * tmpl,GstCaps * caps,MXFEssenceElementWriteFunc * handler,gpointer * mapping_data)458 mxf_up_get_rgba_descriptor (GstPadTemplate * tmpl, GstCaps * caps,
459 MXFEssenceElementWriteFunc * handler, gpointer * mapping_data)
460 {
461 MXFMetadataRGBAPictureEssenceDescriptor *ret;
462 guint i;
463 GstCaps *tmp, *intersection;
464 MXFUPMappingData *md = g_new0 (MXFUPMappingData, 1);
465
466 *mapping_data = md;
467
468 ret = (MXFMetadataRGBAPictureEssenceDescriptor *)
469 g_object_new (MXF_TYPE_METADATA_RGBA_PICTURE_ESSENCE_DESCRIPTOR, NULL);
470
471 for (i = 0; i < G_N_ELEMENTS (_rgba_mapping_table); i++) {
472 tmp = gst_caps_from_string (_rgba_mapping_table[i].caps_string);
473 intersection = gst_caps_intersect (caps, tmp);
474 gst_caps_unref (tmp);
475
476 if (!gst_caps_is_empty (intersection)) {
477 gst_caps_unref (intersection);
478 ret->n_pixel_layout = _rgba_mapping_table[i].n_pixel_layout;
479 ret->pixel_layout = g_new0 (guint8, ret->n_pixel_layout * 2);
480 md->format = _rgba_mapping_table[i].format;
481 md->bpp = _rgba_mapping_table[i].n_pixel_layout;
482 memcpy (ret->pixel_layout, _rgba_mapping_table[i].pixel_layout,
483 ret->n_pixel_layout * 2);
484 break;
485 }
486 gst_caps_unref (intersection);
487 }
488
489 if (md->format == NULL) {
490 GST_ERROR ("Invalid caps %" GST_PTR_FORMAT, caps);
491 g_object_unref (ret);
492 return NULL;
493 }
494
495
496 memcpy (&ret->parent.parent.essence_container, &up_essence_container_ul, 16);
497
498 if (!mxf_metadata_generic_picture_essence_descriptor_from_caps (&ret->parent,
499 caps)) {
500 g_object_unref (ret);
501 return NULL;
502 }
503
504 md->width = ret->parent.stored_width;
505 md->height = ret->parent.stored_height;
506
507 *handler = mxf_up_write_func;
508
509 return (MXFMetadataFileDescriptor *) ret;
510 }
511
512 static MXFMetadataFileDescriptor *
mxf_up_get_cdci_descriptor(GstPadTemplate * tmpl,GstCaps * caps,MXFEssenceElementWriteFunc * handler,gpointer * mapping_data)513 mxf_up_get_cdci_descriptor (GstPadTemplate * tmpl, GstCaps * caps,
514 MXFEssenceElementWriteFunc * handler, gpointer * mapping_data)
515 {
516 MXFMetadataCDCIPictureEssenceDescriptor *ret;
517 guint i;
518 GstCaps *tmp, *intersection;
519 MXFUPMappingData *md = g_new0 (MXFUPMappingData, 1);
520
521 *mapping_data = md;
522
523 ret = (MXFMetadataCDCIPictureEssenceDescriptor *)
524 g_object_new (MXF_TYPE_METADATA_CDCI_PICTURE_ESSENCE_DESCRIPTOR, NULL);
525
526 for (i = 0; i < G_N_ELEMENTS (_cdci_mapping_table); i++) {
527 tmp = gst_caps_from_string (_cdci_mapping_table[i].caps_string);
528 intersection = gst_caps_intersect (caps, tmp);
529 gst_caps_unref (tmp);
530
531 if (!gst_caps_is_empty (intersection)) {
532 gst_caps_unref (intersection);
533 ret->horizontal_subsampling =
534 _cdci_mapping_table[i].horizontal_subsampling;
535 ret->vertical_subsampling = _cdci_mapping_table[i].vertical_subsampling;
536 ret->reversed_byte_order = _cdci_mapping_table[i].reversed_byte_order;
537 md->format = _cdci_mapping_table[i].format;
538 md->bpp = _cdci_mapping_table[i].bpp;
539 break;
540 }
541 gst_caps_unref (intersection);
542 }
543
544 if (md->format == NULL) {
545 GST_ERROR ("Invalid caps %" GST_PTR_FORMAT, caps);
546 g_object_unref (ret);
547 return NULL;
548 }
549
550 memcpy (&ret->parent.parent.essence_container, &up_essence_container_ul, 16);
551
552 if (!mxf_metadata_generic_picture_essence_descriptor_from_caps (&ret->parent,
553 caps)) {
554 g_object_unref (ret);
555 return NULL;
556 }
557
558 md->width = ret->parent.stored_width;
559 md->height = ret->parent.stored_height;
560
561 *handler = mxf_up_write_func;
562
563 return (MXFMetadataFileDescriptor *) ret;
564 }
565
566 static MXFMetadataFileDescriptor *
mxf_up_get_descriptor(GstPadTemplate * tmpl,GstCaps * caps,MXFEssenceElementWriteFunc * handler,gpointer * mapping_data)567 mxf_up_get_descriptor (GstPadTemplate * tmpl, GstCaps * caps,
568 MXFEssenceElementWriteFunc * handler, gpointer * mapping_data)
569 {
570 GstStructure *s;
571
572 s = gst_caps_get_structure (caps, 0);
573 if (strcmp (gst_structure_get_name (s), "video/x-raw") == 0) {
574 const gchar *format;
575
576 format = gst_structure_get_string (s, "format");
577 if (format == NULL)
578 return NULL;
579
580 if (g_str_equal (format, "YUY2") || g_str_equal (format, "UYVY"))
581 return mxf_up_get_cdci_descriptor (tmpl, caps, handler, mapping_data);
582 else
583 return mxf_up_get_rgba_descriptor (tmpl, caps, handler, mapping_data);
584 }
585
586 g_assert_not_reached ();
587 return NULL;
588 }
589
590 static void
mxf_up_update_descriptor(MXFMetadataFileDescriptor * d,GstCaps * caps,gpointer mapping_data,GstBuffer * buf)591 mxf_up_update_descriptor (MXFMetadataFileDescriptor * d, GstCaps * caps,
592 gpointer mapping_data, GstBuffer * buf)
593 {
594 return;
595 }
596
597 static void
mxf_up_get_edit_rate(MXFMetadataFileDescriptor * a,GstCaps * caps,gpointer mapping_data,GstBuffer * buf,MXFMetadataSourcePackage * package,MXFMetadataTimelineTrack * track,MXFFraction * edit_rate)598 mxf_up_get_edit_rate (MXFMetadataFileDescriptor * a, GstCaps * caps,
599 gpointer mapping_data, GstBuffer * buf, MXFMetadataSourcePackage * package,
600 MXFMetadataTimelineTrack * track, MXFFraction * edit_rate)
601 {
602 edit_rate->n = a->sample_rate.n;
603 edit_rate->d = a->sample_rate.d;
604 }
605
606 static guint32
mxf_up_get_track_number_template(MXFMetadataFileDescriptor * a,GstCaps * caps,gpointer mapping_data)607 mxf_up_get_track_number_template (MXFMetadataFileDescriptor * a,
608 GstCaps * caps, gpointer mapping_data)
609 {
610 return (0x15 << 24) | (0x02 << 8);
611 }
612
613 static MXFEssenceElementWriter mxf_up_essence_element_writer = {
614 mxf_up_get_descriptor,
615 mxf_up_update_descriptor,
616 mxf_up_get_edit_rate,
617 mxf_up_get_track_number_template,
618 NULL,
619 {{0,}}
620 };
621
622 void
mxf_up_init(void)623 mxf_up_init (void)
624 {
625 mxf_essence_element_handler_register (&mxf_up_essence_element_handler);
626 mxf_up_essence_element_writer.pad_template =
627 gst_pad_template_new ("up_video_sink_%u", GST_PAD_SINK, GST_PAD_REQUEST,
628 gst_caps_from_string (GST_VIDEO_CAPS_MAKE ("RGB") "; "
629 GST_VIDEO_CAPS_MAKE ("BGR") "; "
630 GST_VIDEO_CAPS_MAKE ("RGBx") "; "
631 GST_VIDEO_CAPS_MAKE ("xRGB") "; "
632 GST_VIDEO_CAPS_MAKE ("BGRx") "; "
633 GST_VIDEO_CAPS_MAKE ("xBGR") "; "
634 GST_VIDEO_CAPS_MAKE ("ARGB") "; "
635 GST_VIDEO_CAPS_MAKE ("RGBA") "; "
636 GST_VIDEO_CAPS_MAKE ("ABGR") "; "
637 GST_VIDEO_CAPS_MAKE ("BGRA") "; "
638 GST_VIDEO_CAPS_MAKE ("AYUV") "; "
639 GST_VIDEO_CAPS_MAKE ("v308") "; "
640 GST_VIDEO_CAPS_MAKE ("UYVY") "; " GST_VIDEO_CAPS_MAKE ("YUY2")));
641
642 memcpy (&mxf_up_essence_element_writer.data_definition,
643 mxf_metadata_track_identifier_get (MXF_METADATA_TRACK_PICTURE_ESSENCE),
644 16);
645 mxf_essence_element_writer_register (&mxf_up_essence_element_writer);
646 }
647