1 /* GStreamer Apple Core Video memory 2 * Copyright (C) 2015 Ilya Konstantinov 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., 59 Temple Place - Suite 330, 17 * Boston, MA 02111-1307, USA. 18 */ 19 20 #ifndef __GST_APPLE_CORE_VIDEO_MEMORY_H__ 21 #define __GST_APPLE_CORE_VIDEO_MEMORY_H__ 22 23 #include <gst/gst.h> 24 25 #include "CoreVideo/CoreVideo.h" 26 27 G_BEGIN_DECLS 28 29 /** 30 * GstAppleCoreVideoLockState: 31 * 32 * Specifies whether the backing CVPixelBuffer is locked for read-only 33 * or read-write. 34 * 35 * Locking for reading only improves performance by preventing 36 * Core Video from invalidating existing caches of the buffer’s contents. 37 */ 38 typedef enum 39 { 40 GST_APPLE_CORE_VIDEO_MEMORY_UNLOCKED, 41 GST_APPLE_CORE_VIDEO_MEMORY_LOCKED_READONLY, 42 GST_APPLE_CORE_VIDEO_MEMORY_LOCKED_READ_WRITE 43 } GstAppleCoreVideoLockState; 44 45 /** 46 * GstAppleCoreVideoPixelBuffer: 47 * 48 * This structure wraps CVPixelBuffer, managing its lock states and reference count. 49 * It will be referenced by one or more #GstAppleCoreVideoMemory. 50 */ 51 typedef struct 52 { 53 guint refcount; 54 GMutex mutex; 55 CVPixelBufferRef buf; 56 /* Allows mem_map to refuse Read-Write locking a buffer that was previously 57 * locked for Read-Only. */ 58 GstAppleCoreVideoLockState lock_state; 59 /* Counts the number of times the buffer was locked. 60 * Only the first lock affects whether it's just for reading 61 * or for reading and writing, as reflected in @lock_state. */ 62 guint lock_count; 63 } GstAppleCoreVideoPixelBuffer; 64 65 /** 66 * GstAppleCoreVideoMemory: 67 * 68 * Represents a video plane or an entire (non-planar) video image, 69 * backed by a CVPixelBuffer. 70 * 71 * This structure shares a #GstAppleCoreVideoPixelBuffer instance 72 * with other instances. 73 */ 74 typedef struct 75 { 76 GstMemory mem; 77 78 GstAppleCoreVideoPixelBuffer *gpixbuf; 79 size_t plane; 80 } GstAppleCoreVideoMemory; 81 82 void 83 gst_apple_core_video_memory_init (void); 84 85 GstAppleCoreVideoPixelBuffer * 86 gst_apple_core_video_pixel_buffer_new (CVPixelBufferRef pixbuf); 87 88 GstAppleCoreVideoPixelBuffer * 89 gst_apple_core_video_pixel_buffer_ref (GstAppleCoreVideoPixelBuffer * shared); 90 91 void 92 gst_apple_core_video_pixel_buffer_unref (GstAppleCoreVideoPixelBuffer * shared); 93 94 gboolean 95 gst_is_apple_core_video_memory (GstMemory * mem); 96 97 GstAppleCoreVideoMemory * 98 gst_apple_core_video_memory_new_wrapped (GstAppleCoreVideoPixelBuffer * shared, gsize plane, gsize size); 99 100 G_END_DECLS 101 102 #endif /* __GST_APPLE_CORE_VIDEO_MEMORY_H__ */ 103