2 * Copyright (C) 2011, Hewlett-Packard Development Company, L.P.
3 * Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>, Collabora Ltd.
4 * Copyright (C) 2013, Collabora Ltd.
5 * Author: Sebastian Dröge <sebastian.droege@collabora.co.uk> *
6 * Copyright 2014 Advanced Micro Devices, Inc.
7 * Author: Christian König <christian.koenig@amd.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation
12 * version 2.1 of the License.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 #include "gstomxvideo.h"
31 GST_DEBUG_CATEGORY (gst_omx_video_debug_category);
32 #define GST_CAT_DEFAULT gst_omx_video_debug_category
35 gst_omx_video_get_format_from_omx (OMX_COLOR_FORMATTYPE omx_colorformat)
37 GstVideoFormat format;
39 switch (omx_colorformat) {
40 case OMX_COLOR_FormatL8:
41 format = GST_VIDEO_FORMAT_GRAY8;
43 case OMX_COLOR_FormatYUV420Planar:
44 case OMX_COLOR_FormatYUV420PackedPlanar:
45 format = GST_VIDEO_FORMAT_I420;
47 case OMX_COLOR_FormatYUV420SemiPlanar:
48 case OMX_COLOR_FormatYUV420PackedSemiPlanar:
49 format = GST_VIDEO_FORMAT_NV12;
51 case OMX_COLOR_FormatYUV422SemiPlanar:
52 format = GST_VIDEO_FORMAT_NV16;
54 case OMX_COLOR_FormatYCbYCr:
55 format = GST_VIDEO_FORMAT_YUY2;
57 case OMX_COLOR_FormatYCrYCb:
58 format = GST_VIDEO_FORMAT_YVYU;
60 case OMX_COLOR_FormatCbYCrY:
61 format = GST_VIDEO_FORMAT_UYVY;
63 case OMX_COLOR_Format32bitARGB8888:
64 /* There is a mismatch in omxil specification 4.2.1 between
65 * OMX_COLOR_Format32bitARGB8888 and its description
66 * Follow the description */
67 format = GST_VIDEO_FORMAT_ABGR;
69 case OMX_COLOR_Format32bitBGRA8888:
70 /* Same issue as OMX_COLOR_Format32bitARGB8888 */
71 format = GST_VIDEO_FORMAT_ARGB;
73 case OMX_COLOR_Format16bitRGB565:
74 format = GST_VIDEO_FORMAT_RGB16;
76 case OMX_COLOR_Format16bitBGR565:
77 format = GST_VIDEO_FORMAT_BGR16;
79 case OMX_COLOR_Format24bitBGR888:
80 format = GST_VIDEO_FORMAT_BGR;
83 format = GST_VIDEO_FORMAT_UNKNOWN;
91 gst_omx_video_get_supported_colorformats (GstOMXPort * port,
92 GstVideoCodecState * state)
94 GstOMXComponent *comp = port->comp;
95 OMX_VIDEO_PARAM_PORTFORMATTYPE param;
97 GList *negotiation_map = NULL;
99 GstOMXVideoNegotiationMap *m;
102 GST_OMX_INIT_STRUCT (¶m);
103 param.nPortIndex = port->index;
105 if (!state || state->info.fps_n == 0)
106 param.xFramerate = 0;
108 param.xFramerate = (state->info.fps_n << 16) / (state->info.fps_d);
113 gst_omx_component_get_parameter (comp,
114 OMX_IndexParamVideoPortFormat, ¶m);
116 /* FIXME: Workaround for Bellagio that simply always
117 * returns the same value regardless of nIndex and
118 * never returns OMX_ErrorNoMore
120 if (old_index == param.nIndex)
123 if (err == OMX_ErrorNone || err == OMX_ErrorNoMore) {
124 f = gst_omx_video_get_format_from_omx (param.eColorFormat);
126 if (f != GST_VIDEO_FORMAT_UNKNOWN) {
127 m = g_slice_new (GstOMXVideoNegotiationMap);
129 m->type = param.eColorFormat;
130 negotiation_map = g_list_append (negotiation_map, m);
131 GST_DEBUG_OBJECT (comp->parent,
132 "Component supports %s (%d) at index %u",
133 gst_video_format_to_string (f), param.eColorFormat,
134 (guint) param.nIndex);
136 GST_DEBUG_OBJECT (comp->parent,
137 "Component supports unsupported color format %d at index %u",
138 param.eColorFormat, (guint) param.nIndex);
141 old_index = param.nIndex++;
142 } while (err == OMX_ErrorNone);
144 return negotiation_map;
148 gst_omx_video_get_caps_for_map (GList * map)
150 GstCaps *caps = gst_caps_new_empty ();
153 for (l = map; l; l = l->next) {
154 GstOMXVideoNegotiationMap *entry = l->data;
156 gst_caps_append_structure (caps,
157 gst_structure_new ("video/x-raw",
158 "format", G_TYPE_STRING,
159 gst_video_format_to_string (entry->format), NULL));
165 gst_omx_video_negotiation_map_free (GstOMXVideoNegotiationMap * m)
167 g_slice_free (GstOMXVideoNegotiationMap, m);
171 gst_omx_video_find_nearest_frame (GstOMXBuffer * buf, GList * frames)
173 GstVideoCodecFrame *best = NULL;
174 GstClockTimeDiff best_diff = G_MAXINT64;
175 GstClockTime timestamp;
179 gst_util_uint64_scale (GST_OMX_GET_TICKS (buf->omx_buf->nTimeStamp),
180 GST_SECOND, OMX_TICKS_PER_SECOND);
182 for (l = frames; l; l = l->next) {
183 GstVideoCodecFrame *tmp = l->data;
184 GstClockTimeDiff diff = ABS (GST_CLOCK_DIFF (timestamp, tmp->pts));
186 if (diff < best_diff) {
196 gst_video_codec_frame_ref (best);
198 g_list_foreach (frames, (GFunc) gst_video_codec_frame_unref, NULL);
199 g_list_free (frames);