• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * gstxcambuffermeta.cpp - gst xcam buffer meta data
3  *
4  *  Copyright (c) 2014-2015 Intel Corporation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * Author: Wind Yuan <feng.yuan@intel.com>
19  */
20 
21 #include "gstxcambuffermeta.h"
22 
23 using namespace XCam;
24 
25 GType
gst_xcam_buffer_meta_api_get_type(void)26 gst_xcam_buffer_meta_api_get_type (void)
27 {
28     static GType xcam_buf_type = 0;
29     static const gchar *xcam_buf_tags [] =
30     { GST_XCAM_META_TAG_XCAM, GST_XCAM_META_TAG_BUF, NULL };
31 
32     if (g_once_init_enter (&xcam_buf_type)) {
33         GType _type = gst_meta_api_type_register ("GstXCamBuffer", xcam_buf_tags);
34         g_once_init_leave (&xcam_buf_type, _type);
35     }
36 
37     return xcam_buf_type;
38 }
39 
40 static gboolean
gst_xcam_buffer_meta_init(GstMeta * base,gpointer params,GstBuffer * buffer)41 gst_xcam_buffer_meta_init (GstMeta *base, gpointer params, GstBuffer *buffer)
42 {
43     XCAM_UNUSED (params);
44     XCAM_UNUSED (buffer);
45     GstXCamBufferMeta *meta = (GstXCamBufferMeta *)base;
46 
47     XCAM_CONSTRUCTOR (meta->buffer, SmartPtr<VideoBuffer>);
48     return TRUE;
49 }
50 
51 
52 static void
gst_xcam_buffer_meta_free(GstMeta * base,GstBuffer * buffer)53 gst_xcam_buffer_meta_free (GstMeta *base, GstBuffer *buffer)
54 {
55     XCAM_UNUSED (buffer);
56     GstXCamBufferMeta *meta = (GstXCamBufferMeta *)base;
57 
58     meta->buffer->unmap ();
59     XCAM_DESTRUCTOR (meta->buffer, SmartPtr<VideoBuffer>);
60 }
61 
62 static const GstMetaInfo *
gst_xcam_buffer_meta_get_info(void)63 gst_xcam_buffer_meta_get_info (void)
64 {
65     static const GstMetaInfo *meta_info = NULL;
66 
67     if (g_once_init_enter (&meta_info)) {
68         const GstMetaInfo *_meta =
69             gst_meta_register (GST_XCAM_BUFFER_META_API_TYPE,
70                                "GstXCamBufferMeta",
71                                sizeof (GstXCamBufferMeta),
72                                gst_xcam_buffer_meta_init,
73                                gst_xcam_buffer_meta_free,
74                                NULL);
75         g_once_init_leave (&meta_info, _meta);
76     }
77     return meta_info;
78 }
79 
80 GstXCamBufferMeta *
gst_buffer_add_xcam_buffer_meta(GstBuffer * buffer,const SmartPtr<VideoBuffer> & data)81 gst_buffer_add_xcam_buffer_meta (
82     GstBuffer *buffer,
83     const SmartPtr<VideoBuffer>  &data)
84 {
85     XCAM_ASSERT (data.ptr ());
86 
87     GstXCamBufferMeta *meta = (GstXCamBufferMeta*) gst_buffer_add_meta (
88                                   buffer, gst_xcam_buffer_meta_get_info(), NULL);
89 
90     g_return_val_if_fail (meta, NULL);
91 
92     meta->buffer = data;
93 
94     return meta;
95 }
96 
97 
98