Line data Source code
1 : /*
2 : * GPAC - Multimedia Framework C SDK
3 : *
4 : * Authors: Deniz Ugur, Romain Bouqueau, Sohaib Larbi
5 : * Copyright (c) Motion Spell
6 : * All rights reserved
7 : *
8 : * This file is part of the GPAC/GStreamer wrapper
9 : *
10 : * This GPAC/GStreamer wrapper is free software; you can redistribute it
11 : * and/or modify it under the terms of the GNU Affero General Public License
12 : * as published by the Free Software Foundation; either version 3, or (at
13 : * your option) any later version.
14 : *
15 : * This GPAC/GStreamer wrapper is distributed in the hope that it will be
16 : * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
17 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 : * GNU Affero General Public License for more details.
19 : *
20 : * You should have received a copy of the GNU Affero General Public
21 : * License along with this library; see the file LICENSE. If not, write to
22 : * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23 : *
24 : */
25 :
26 : #include "common.h"
27 : #include "lib/memio.h"
28 :
29 : typedef struct
30 : {
31 : GQueue* output_queue;
32 : } GenericCtx;
33 :
34 : void
35 0 : generic_ctx_init(void** process_ctx)
36 : {
37 0 : *process_ctx = g_new0(GenericCtx, 1);
38 0 : GenericCtx* ctx = (GenericCtx*)*process_ctx;
39 0 : ctx->output_queue = g_queue_new();
40 0 : }
41 :
42 : void
43 0 : generic_ctx_free(void* process_ctx)
44 : {
45 0 : GenericCtx* ctx = (GenericCtx*)process_ctx;
46 :
47 : // Free the output queue
48 0 : while (!g_queue_is_empty(ctx->output_queue))
49 0 : gst_buffer_unref((GstBuffer*)g_queue_pop_head(ctx->output_queue));
50 0 : g_queue_free(ctx->output_queue);
51 :
52 : // Free the context
53 0 : g_free(ctx);
54 0 : }
55 :
56 : GF_Err
57 0 : generic_configure_pid(GF_Filter* filter, GF_FilterPid* pid)
58 : {
59 0 : return GF_OK;
60 : }
61 :
62 : Bool
63 0 : generic_process_event(GF_Filter* filter, const GF_FilterEvent* evt)
64 : {
65 0 : return GF_FALSE; // No event processing
66 : }
67 :
68 : GF_Err
69 0 : generic_post_process(GF_Filter* filter, GF_FilterPid* pid, GF_FilterPacket* pck)
70 : {
71 : GPAC_MemOutPIDContext* ctx =
72 0 : (GPAC_MemOutPIDContext*)gf_filter_pid_get_udta(pid);
73 0 : GenericCtx* generic_ctx = (GenericCtx*)ctx->private_ctx;
74 :
75 0 : if (!pck)
76 0 : return GF_OK;
77 :
78 : // Get the data
79 : u32 size;
80 0 : const u8* data = gf_filter_pck_get_data(pck, &size);
81 0 : gf_filter_pck_ref(&pck);
82 :
83 : // Create a new buffer
84 : GstBuffer* buffer =
85 0 : gst_buffer_new_wrapped_full(GST_MEMORY_FLAG_READONLY, // flags
86 : (u8*)data, // data
87 : size, // maxsize
88 : 0, // offset
89 : size, // size
90 : pck, // user_data
91 : (GDestroyNotify)gf_filter_pck_unref // notify
92 : );
93 :
94 : // Enqueue the buffer
95 0 : g_queue_push_tail(generic_ctx->output_queue, buffer);
96 0 : return GF_OK;
97 : }
98 :
99 : GPAC_FilterPPRet
100 0 : generic_consume(GF_Filter* filter, GF_FilterPid* pid, void** outptr)
101 : {
102 : GPAC_MemOutPIDContext* ctx =
103 0 : (GPAC_MemOutPIDContext*)gf_filter_pid_get_udta(pid);
104 0 : GenericCtx* generic_ctx = (GenericCtx*)ctx->private_ctx;
105 :
106 : // Check if the queue is empty
107 0 : if (g_queue_is_empty(generic_ctx->output_queue))
108 0 : return GPAC_FILTER_PP_RET_EMPTY;
109 :
110 : // Assign the output
111 0 : if (outptr) {
112 0 : *outptr = g_queue_pop_head(generic_ctx->output_queue);
113 0 : return GPAC_FILTER_PP_RET_BUFFER;
114 : }
115 0 : return GPAC_FILTER_PP_RET_NULL;
116 : }
|