Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim:set ts=2 sw=2 sts=2 et cindent: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 5 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include <string.h> |
michael@0 | 8 | #include "GStreamerReader.h" |
michael@0 | 9 | #include "GStreamerMozVideoBuffer.h" |
michael@0 | 10 | #include "ImageContainer.h" |
michael@0 | 11 | |
michael@0 | 12 | namespace mozilla { |
michael@0 | 13 | |
michael@0 | 14 | static GstMozVideoBuffer *gst_moz_video_buffer_copy(GstMozVideoBuffer* self); |
michael@0 | 15 | static void gst_moz_video_buffer_finalize(GstMozVideoBuffer* self); |
michael@0 | 16 | |
michael@0 | 17 | // working around GTK+ bug https://bugzilla.gnome.org/show_bug.cgi?id=723899 |
michael@0 | 18 | #pragma GCC diagnostic push |
michael@0 | 19 | #pragma GCC diagnostic ignored "-Wunused-function" |
michael@0 | 20 | G_DEFINE_TYPE(GstMozVideoBuffer, gst_moz_video_buffer, GST_TYPE_BUFFER); |
michael@0 | 21 | #pragma GCC diagnostic pop |
michael@0 | 22 | |
michael@0 | 23 | static void |
michael@0 | 24 | gst_moz_video_buffer_class_init(GstMozVideoBufferClass* klass) |
michael@0 | 25 | { |
michael@0 | 26 | g_return_if_fail(GST_IS_MOZ_VIDEO_BUFFER_CLASS(klass)); |
michael@0 | 27 | |
michael@0 | 28 | GstMiniObjectClass *mo_class = GST_MINI_OBJECT_CLASS(klass); |
michael@0 | 29 | |
michael@0 | 30 | mo_class->copy =(GstMiniObjectCopyFunction)gst_moz_video_buffer_copy; |
michael@0 | 31 | mo_class->finalize =(GstMiniObjectFinalizeFunction)gst_moz_video_buffer_finalize; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | static void |
michael@0 | 35 | gst_moz_video_buffer_init(GstMozVideoBuffer* self) |
michael@0 | 36 | { |
michael@0 | 37 | g_return_if_fail(GST_IS_MOZ_VIDEO_BUFFER(self)); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | static void |
michael@0 | 41 | gst_moz_video_buffer_finalize(GstMozVideoBuffer* self) |
michael@0 | 42 | { |
michael@0 | 43 | g_return_if_fail(GST_IS_MOZ_VIDEO_BUFFER(self)); |
michael@0 | 44 | |
michael@0 | 45 | if(self->data) |
michael@0 | 46 | g_boxed_free(GST_TYPE_MOZ_VIDEO_BUFFER_DATA, self->data); |
michael@0 | 47 | |
michael@0 | 48 | GST_MINI_OBJECT_CLASS(gst_moz_video_buffer_parent_class)->finalize(GST_MINI_OBJECT(self)); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | static GstMozVideoBuffer* |
michael@0 | 52 | gst_moz_video_buffer_copy(GstMozVideoBuffer* self) |
michael@0 | 53 | { |
michael@0 | 54 | GstMozVideoBuffer* copy; |
michael@0 | 55 | |
michael@0 | 56 | g_return_val_if_fail(GST_IS_MOZ_VIDEO_BUFFER(self), nullptr); |
michael@0 | 57 | |
michael@0 | 58 | copy = gst_moz_video_buffer_new(); |
michael@0 | 59 | |
michael@0 | 60 | /* we simply copy everything from our parent */ |
michael@0 | 61 | GST_BUFFER_DATA(GST_BUFFER_CAST(copy)) = |
michael@0 | 62 | (guint8*)g_memdup(GST_BUFFER_DATA(GST_BUFFER_CAST(self)), GST_BUFFER_SIZE(GST_BUFFER_CAST(self))); |
michael@0 | 63 | |
michael@0 | 64 | /* make sure it gets freed(even if the parent is subclassed, we return a |
michael@0 | 65 | normal buffer) */ |
michael@0 | 66 | GST_BUFFER_MALLOCDATA(GST_BUFFER_CAST(copy)) = GST_BUFFER_DATA(GST_BUFFER_CAST(copy)); |
michael@0 | 67 | GST_BUFFER_SIZE(GST_BUFFER_CAST(copy)) = GST_BUFFER_SIZE(GST_BUFFER_CAST(self)); |
michael@0 | 68 | |
michael@0 | 69 | /* copy metadata */ |
michael@0 | 70 | gst_buffer_copy_metadata(GST_BUFFER_CAST(copy), |
michael@0 | 71 | GST_BUFFER_CAST(self), |
michael@0 | 72 | (GstBufferCopyFlags)GST_BUFFER_COPY_ALL); |
michael@0 | 73 | /* copy videobuffer */ |
michael@0 | 74 | if(self->data) |
michael@0 | 75 | copy->data = (GstMozVideoBufferData*)g_boxed_copy(GST_TYPE_MOZ_VIDEO_BUFFER_DATA, self->data); |
michael@0 | 76 | |
michael@0 | 77 | return copy; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | GstMozVideoBuffer* |
michael@0 | 81 | gst_moz_video_buffer_new(void) |
michael@0 | 82 | { |
michael@0 | 83 | GstMozVideoBuffer *self; |
michael@0 | 84 | |
michael@0 | 85 | self =(GstMozVideoBuffer*)gst_mini_object_new(GST_TYPE_MOZ_VIDEO_BUFFER); |
michael@0 | 86 | self->data = nullptr; |
michael@0 | 87 | |
michael@0 | 88 | return self; |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | void |
michael@0 | 92 | gst_moz_video_buffer_set_data(GstMozVideoBuffer* self, GstMozVideoBufferData* data) |
michael@0 | 93 | { |
michael@0 | 94 | g_return_if_fail(GST_IS_MOZ_VIDEO_BUFFER(self)); |
michael@0 | 95 | |
michael@0 | 96 | self->data = data; |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | GstMozVideoBufferData* |
michael@0 | 100 | gst_moz_video_buffer_get_data(const GstMozVideoBuffer* self) |
michael@0 | 101 | { |
michael@0 | 102 | g_return_val_if_fail(GST_IS_MOZ_VIDEO_BUFFER(self), nullptr); |
michael@0 | 103 | |
michael@0 | 104 | return self->data; |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | GType |
michael@0 | 108 | gst_moz_video_buffer_data_get_type(void) |
michael@0 | 109 | { |
michael@0 | 110 | static volatile gsize g_define_type_id__volatile = 0; |
michael@0 | 111 | |
michael@0 | 112 | if(g_once_init_enter(&g_define_type_id__volatile)) { |
michael@0 | 113 | GType g_define_type_id = |
michael@0 | 114 | g_boxed_type_register_static(g_intern_static_string("GstMozVideoBufferData"), |
michael@0 | 115 | (GBoxedCopyFunc)GstMozVideoBufferData::Copy, |
michael@0 | 116 | (GBoxedFreeFunc)GstMozVideoBufferData::Free); |
michael@0 | 117 | g_once_init_leave(&g_define_type_id__volatile, g_define_type_id); |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | return g_define_type_id__volatile; |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | } |