1/* 2 * Copyright (C) 2010 Ole André Vadla Ravnås <oleavr@soundrop.com> 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#ifdef HAVE_CONFIG_H 21# include "config.h" 22#endif 23 24#if !HAVE_IOS 25#import <AppKit/AppKit.h> 26#endif 27#include "videotexturecache.h" 28#include "coremediabuffer.h" 29#include "corevideobuffer.h" 30#include "vtutil.h" 31 32G_DEFINE_ABSTRACT_TYPE (GstVideoTextureCache, gst_video_texture_cache, G_TYPE_OBJECT); 33 34static void gst_video_texture_cache_default_set_format (GstVideoTextureCache * cache, 35 GstVideoFormat in_format, GstCaps * out_caps); 36 37static void 38gst_video_texture_cache_finalize (GObject * object) 39{ 40 GstVideoTextureCache *cache = GST_VIDEO_TEXTURE_CACHE (object); 41 42 if (cache->in_caps) 43 gst_caps_unref (cache->in_caps); 44 if (cache->out_caps) 45 gst_caps_unref (cache->out_caps); 46 47 G_OBJECT_CLASS (gst_video_texture_cache_parent_class)->finalize (object); 48} 49 50static void 51gst_video_texture_cache_init (GstVideoTextureCache * cache) 52{ 53 gst_video_info_init (&cache->input_info); 54} 55 56static void 57gst_video_texture_cache_class_init (GstVideoTextureCacheClass *klass) 58{ 59 GObjectClass *gobject_class = G_OBJECT_CLASS (klass); 60 61 gobject_class->finalize = gst_video_texture_cache_finalize; 62 63 klass->set_format = gst_video_texture_cache_default_set_format; 64} 65 66static void 67gst_video_texture_cache_default_set_format (GstVideoTextureCache * cache, 68 GstVideoFormat in_format, GstCaps * out_caps) 69{ 70 GstCaps *in_caps; 71 72 g_return_if_fail (gst_caps_is_fixed (out_caps)); 73 74 out_caps = gst_caps_copy (out_caps); 75 gst_video_info_from_caps (&cache->output_info, out_caps); 76 77 in_caps = gst_caps_copy (out_caps); 78 gst_caps_set_simple (in_caps, "format", 79 G_TYPE_STRING, gst_video_format_to_string (in_format), NULL); 80 gst_video_info_from_caps (&cache->input_info, in_caps); 81 82 gst_caps_take (&cache->in_caps, in_caps); 83 gst_caps_take (&cache->out_caps, out_caps); 84} 85 86void 87gst_video_texture_cache_set_format (GstVideoTextureCache * cache, 88 GstVideoFormat in_format, GstCaps * out_caps) 89{ 90 GstVideoTextureCacheClass *cache_class = GST_VIDEO_TEXTURE_CACHE_GET_CLASS (cache); 91 92 g_return_if_fail (cache_class->set_format); 93 cache_class->set_format (cache, in_format, out_caps); 94} 95 96GstMemory * 97gst_video_texture_cache_create_memory (GstVideoTextureCache * cache, 98 GstAppleCoreVideoPixelBuffer *gpixbuf, guint plane, gsize size) 99{ 100 GstVideoTextureCacheClass *cache_class = GST_VIDEO_TEXTURE_CACHE_GET_CLASS (cache); 101 102 g_return_val_if_fail (cache_class->create_memory, NULL); 103 return cache_class->create_memory (cache, gpixbuf, plane, size); 104} 105