The example:
<br><br>appsrc-stream.c: example for using appsrc in streaming mode.
<br><br>Fits the bill. It loads a file as a memory map but if you shoehorn in
<br>your memory location and size at lines:
<br><br>207          app->length = g_mapped_file_get_length (app->file);
<br>208          app->data = (guint8 *) g_mapped_file_get_contents (app->file);
<br><br>You'll have a working example of what I was after.
<br><br>Cheers,
<br>Brad
<br><br><br><br><br>1         /* GStreamer
<br>2          *
<br>3          * appsrc-stream.c: example for using appsrc in streaming mode.
<br>4          *
<br>5          * Copyright (C) 2008 Wim Taymans <<a href="/user/SendEmail.jtp?type=node&node=3174994&i=0" target="_top" rel="nofollow">[hidden email]</a>>
<br>6          *
<br>7          * This library is free software; you can redistribute it and/or
<br>8          * modify it under the terms of the GNU Library General Public
<br>9          * License as published by the Free Software Foundation; either
<br>10          * version 2 of the License, or (at your option) any later version.
<br>11          *
<br>12          * This library is distributed in the hope that it will be useful,
<br>13          * but WITHOUT ANY WARRANTY; without even the implied warranty of
<br>14          * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
<br>15          * Library General Public License for more details.
<br>16          *
<br>17          * You should have received a copy of the GNU Library General Public
<br>18          * License along with this library; if not, write to the
<br>19          * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
<br>20          * Boston, MA 02111-1307, USA.
<br>21          */
<br>22         
<br>23         #ifdef HAVE_CONFIG_H
<br>24         #include "config.h"
<br>25         #endif
<br>26         
<br>27         #include <gst/gst.h>
<br>28         
<br>29         #include <stdio.h>
<br>30         #include <string.h>
<br>31         #include <stdlib.h>
<br>32         
<br>33         GST_DEBUG_CATEGORY (appsrc_playbin_debug);
<br>34         #define GST_CAT_DEFAULT appsrc_playbin_debug
<br>35         
<br>36         /*
<br>37          * an example application of using appsrc in streaming push mode.
<br>We simply push
<br>38          * buffers into appsrc. The size of the buffers we push can be any size we
<br>39          * choose.
<br>40          *
<br>41          * This example is very close to how one would deal with a
<br>streaming webserver
<br>42          * that does not support range requests or does not report the
<br>total file size.
<br>43          *
<br>44          * Some optimisations are done so that we don't push too much
<br>data. We connect
<br>45          * to the need-data and enough-data signals to start/stop sending buffers.
<br>46          *
<br>47          * Appsrc in streaming mode (the default) does not support seeking
<br>so we don't
<br>48          * have to handle any seek callbacks.
<br>49          *
<br>50          * Some formats are able to estimate the duration of the media
<br>file based on the
<br>51          * file length (mp3, mpeg,..), others report an unknown length (ogg,..).
<br>52          */
<br>53         typedef struct _App App;
<br>54         
<br>55         struct _App
<br>56         {
<br>57          GstElement *playbin;
<br>58          GstElement *appsrc;
<br>59         
<br>60          GMainLoop *loop;
<br>61          guint sourceid;
<br>62         
<br>63          GMappedFile *file;
<br>64          guint8 *data;
<br>65          gsize length;
<br>66          guint64 offset;
<br>67         };
<br>68         
<br>69         App s_app;
<br>70         
<br>71         #define CHUNK_SIZE 4096
<br>72         
<br>73         /* This method is called by the idle GSource in the mainloop. We
<br>feed CHUNK_SIZE
<br>74          * bytes into appsrc.
<br>75          * The ide handler is added to the mainloop when appsrc requests us to start
<br>76          * sending data (need-data signal) and is removed when appsrc has
<br>enough data
<br>77          * (enough-data signal).
<br>78          */
<br>79         static gboolean
<br>80         read_data (App * app)
<br>81         {
<br>82          GstBuffer *buffer;
<br>83          guint len;
<br>84          GstFlowReturn ret;
<br>85         
<br>86          buffer = gst_buffer_new ();
<br>87         
<br>88          if (app->offset >= app->length) {
<br>89          /* we are EOS, send end-of-stream and remove the source */
<br>90          g_signal_emit_by_name (app->appsrc, "end-of-stream", &ret);
<br>91          return FALSE;
<br>92          }
<br>93         
<br>94          /* read the next chunk */
<br>95          len = CHUNK_SIZE;
<br>96          if (app->offset + len > app->length)
<br>97          len = app->length - app->offset;
<br>98         
<br>99          GST_BUFFER_DATA (buffer) = app->data + app->offset;
<br>100          GST_BUFFER_SIZE (buffer) = len;
<br>101         
<br>102          GST_DEBUG ("feed buffer %p, offset %" G_GUINT64_FORMAT "-%u", buffer,
<br>103          app->offset, len);
<br>104          g_signal_emit_by_name (app->appsrc, "push-buffer", buffer, &ret);
<br>105          if (ret != GST_FLOW_OK) {
<br>106          /* some error, stop sending data */
<br>107          return FALSE;
<br>108          }
<br>109         
<br>110          app->offset += len;
<br>111         
<br>112          return TRUE;
<br>113         }
<br>114         
<br>115         /* This signal callback is called when appsrc needs data, we add
<br>an idle handler
<br>116          * to the mainloop to start pushing data into the appsrc */
<br>117         static void
<br>118         start_feed (GstElement * playbin, guint size, App * app)
<br>119         {
<br>120          if (app->sourceid == 0) {
<br>121          GST_DEBUG ("start feeding");
<br>122          app->sourceid = g_idle_add ((GSourceFunc) read_data, app);
<br>123          }
<br>124         }
<br>125         
<br>126         /* This callback is called when appsrc has enough data and we can
<br>stop sending.
<br>127          * We remove the idle handler from the mainloop */
<br>128         static void
<br>129         stop_feed (GstElement * playbin, App * app)
<br>130         {
<br>131          if (app->sourceid != 0) {
<br>132          GST_DEBUG ("stop feeding");
<br>133          g_source_remove (app->sourceid);
<br>134          app->sourceid = 0;
<br>135          }
<br>136         }
<br>137         
<br>138         /* this callback is called when playbin2 has constructed a source
<br>object to read
<br>139          * from. Since we provided the appsrc:// uri to playbin2, this will be the
<br>140          * appsrc that we must handle. We set up some signals to start
<br>and stop pushing
<br>141          * data into appsrc */
<br>142         static void
<br>143         found_source (GObject * object, GObject * orig, GParamSpec *
<br>pspec, App * app)
<br>144         {
<br>145          /* get a handle to the appsrc */
<br>146          g_object_get (orig, pspec->name, &app->appsrc, NULL);
<br>147         
<br>148          GST_DEBUG ("got appsrc %p", app->appsrc);
<br>149         
<br>150          /* we can set the length in appsrc. This allows some elements
<br>to estimate the
<br>151          * total duration of the stream. It's a good idea to set the
<br>property when you
<br>152          * can but it's not required. */
<br>153          g_object_set (app->appsrc, "size", app->length, NULL);
<br>154         
<br>155          /* configure the appsrc, we will push data into the appsrc from the
<br>156          * mainloop. */
<br>157          g_signal_connect (app->appsrc, "need-data", G_CALLBACK
<br>(start_feed), app);
<br>158          g_signal_connect (app->appsrc, "enough-data", G_CALLBACK
<br>(stop_feed), app);
<br>159         }
<br>160         
<br>161         static gboolean
<br>162         bus_message (GstBus * bus, GstMessage * message, App * app)
<br>163         {
<br>164          GST_DEBUG ("got message %s",
<br>165          gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
<br>166         
<br>167          switch (GST_MESSAGE_TYPE (message)) {
<br>168          case GST_MESSAGE_ERROR:
<br>169          g_error ("received error");
<br>170          g_main_loop_quit (app->loop);
<br>171          break;
<br>172          case GST_MESSAGE_EOS:
<br>173          g_main_loop_quit (app->loop);
<br>174          break;
<br>175          default:
<br>176          break;
<br>177          }
<br>178          return TRUE;
<br>179         }
<br>180         
<br>181         int
<br>182         main (int argc, char *argv[])
<br>183         {
<br>184          App *app = &s_app;
<br>185          GError *error = NULL;
<br>186          GstBus *bus;
<br>187         
<br>188          gst_init (&argc, &argv);
<br>189         
<br>190          GST_DEBUG_CATEGORY_INIT (appsrc_playbin_debug, "appsrc-playbin", 0,
<br>191          "appsrc playbin example");
<br>192         
<br>193          if (argc < 2) {
<br>194          g_print ("usage: %s <filename>\n", argv[0]);
<br>195          return -1;
<br>196          }
<br>197         
<br>198          /* try to open the file as an mmapped file */
<br>199          app->file = g_mapped_file_new (argv[1], FALSE, &error);
<br>200          if (error) {
<br>201          g_print ("failed to open file: %s\n", error->message);
<br>202          g_error_free (error);
<br>203          return -2;
<br>204          }
<br>205          /* get some vitals, this will be used to read data from the
<br>mmapped file and
<br>206          * feed it to appsrc. */
<br>207          app->length = g_mapped_file_get_length (app->file);
<br>208          app->data = (guint8 *) g_mapped_file_get_contents (app->file);
<br>209          app->offset = 0;
<br>210         
<br>211          /* create a mainloop to get messages and to handle the idle
<br>handler that will
<br>212          * feed data to appsrc. */
<br>213          app->loop = g_main_loop_new (NULL, TRUE);
<br>214         
<br>215          app->playbin = gst_element_factory_make ("playbin2", NULL);
<br>216          g_assert (app->playbin);
<br>217         
<br>218          bus = gst_pipeline_get_bus (GST_PIPELINE (app->playbin));
<br>219         
<br>220          /* add watch for messages */
<br>221          gst_bus_add_watch (bus, (GstBusFunc) bus_message, app);
<br>222         
<br>223          /* set to read from appsrc */
<br>224          g_object_set (app->playbin, "uri", "appsrc://", NULL);
<br>225         
<br>226          /* get notification when the source is created so that we get a
<br>handle to it
<br>227          * and can configure it */
<br>228          g_signal_connect (app->playbin, "deep-notify::source",
<br>229          (GCallback) found_source, app);
<br>230         
<br>231          /* go to playing and wait in a mainloop. */
<br>232          gst_element_set_state (app->playbin, GST_STATE_PLAYING);
<br>233         
<br>234          /* this mainloop is stopped when we receive an error or EOS */
<br>235          g_main_loop_run (app->loop);
<br>236         
<br>237          GST_DEBUG ("stopping");
<br>238         
<br>239          gst_element_set_state (app->playbin, GST_STATE_NULL);
<br>240         
<br>241          /* free the file */
<br>242          g_mapped_file_free (app->file);
<br>243         
<br>244          gst_object_unref (bus);
<br>245          g_main_loop_unref (app->loop);
<br>246         
<br>247          return 0;
<br>248         }
<br><br><br>On Wed, Jan 5, 2011 at 5:30 PM, <a href="/user/SendEmail.jtp?type=node&node=3174994&i=1" target="_top" rel="nofollow">[hidden email]</a> [via
<br>GStreamer-devel] <<a href="/user/SendEmail.jtp?type=node&node=3174994&i=2" target="_top" rel="nofollow">[hidden email]</a>>
<br>wrote:
<div class='shrinkable-quote'><br>> It can be put in the pipeline. But you need to pump data into it from your
<br>> application. Your application would be (sort of) the 'source' and appsrc is
<br>> like a cheat code to make the following elements think that there is
<br>> actually a source element in there at the start of the pipeline feeding them
<br>> gstbuffers.
<br>> Try looking up the output format of filesrc element and package your data
<br>> similarly and feed it to appsrc. Rest will be taken care by the
<br>> bin/pipeline.
<br>> Rohit
<br>> On Wed, Jan 5, 2011 at 11:34 AM, Brad Goldsmith <[hidden email]> wrote:
<br>>>
<br>>> Can appsrc be put in that pipeline, in place of filesrc, without any
<br>>> additional elements?
<br>>>
<br>>> Cheers,
<br>>> Brad
<br>>>
<br>>> On Wed, Jan 5, 2011 at 1:55 AM, Tim-Philipp Müller <[hidden email]> wrote:
<br>>> > On Tue, 2011-01-04 at 04:35 -0800, bcg wrote:
<br>>> >
<br>>> > Hi,
<br>>> >
<br>>> >> This should almost be an FAQ but it's not in there so here goes:
<br>>> >>
<br>>> >> I have a pipeline thus:
<br>>> >>
<br>>> >> file-source -> decodebin -> audioresample -> converter -> audio_output
<br>>> >>
<br>>> >> Using location (or fd if I change file_source to a fdsrc) I can happily
<br>>> >> play
<br>>> >> most audio I throw at it (including mp3s) providing its in a file. What
<br>>> >> I
<br>>> >> would like to do is play from a memory location with the mp3 data
<br>>> >> already in
<br>>> >> it.
<br>>> >>
<br>>> >> I am assuming I would need to use a fakesrc with a callback to get my
<br>>> >> data
<br>>> >> into the pipeline - I've tried lots of variations on this and gotten
<br>>> >> nowhere.
<br>>> >>
<br>>> >> Can I just replace the file-source with the fakesrc, load the data and
<br>>> >> go
<br>>> >> (if this is possible couple someone provide an example)? Or do I have
<br>>> >> to
<br>>> >> worry about queues and caps? If so, can someone provide an example?
<br>>> >> Will
<br>>> >> decodebin suffice or will I have to be more specific?
<br>>> >
<br>>> > Use appsrc.
<br>>> >
<br>>> > Cheers
<br>>> > -Tim
<br>>> >
<br>>> >
<br>>> >
<br>>> >
<br>>> > ------------------------------------------------------------------------------
<br>>> > Learn how Oracle Real Application Clusters (RAC) One Node allows
<br>>> > customers
<br>>> > to consolidate database storage, standardize their database environment,
<br>>> > and,
<br>>> > should the need arise, upgrade to a full multi-node Oracle RAC database
<br>>> > without downtime or disruption
<br>>> > <a href="http://p.sf.net/sfu/oracle-sfdevnl" target="_top" rel="nofollow" link="external">http://p.sf.net/sfu/oracle-sfdevnl</a><br>>> > _______________________________________________
<br>>> > gstreamer-devel mailing list
<br>>> > [hidden email]
<br>>> > <a href="https://lists.sourceforge.net/lists/listinfo/gstreamer-devel" target="_top" rel="nofollow" link="external">https://lists.sourceforge.net/lists/listinfo/gstreamer-devel</a><br>>> >
<br>>>
<br>>>
<br>>> ------------------------------------------------------------------------------
<br>>> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
<br>>> to consolidate database storage, standardize their database environment,
<br>>> and,
<br>>> should the need arise, upgrade to a full multi-node Oracle RAC database
<br>>> without downtime or disruption
<br>>> <a href="http://p.sf.net/sfu/oracle-sfdevnl" target="_top" rel="nofollow" link="external">http://p.sf.net/sfu/oracle-sfdevnl</a><br>>> _______________________________________________
<br>>> gstreamer-devel mailing list
<br>>> [hidden email]
<br>>> <a href="https://lists.sourceforge.net/lists/listinfo/gstreamer-devel" target="_top" rel="nofollow" link="external">https://lists.sourceforge.net/lists/listinfo/gstreamer-devel</a><br>>
<br>>
<br>> ------------------------------------------------------------------------------
<br>> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
<br>> to consolidate database storage, standardize their database environment,
<br>> and,
<br>> should the need arise, upgrade to a full multi-node Oracle RAC database
<br>> without downtime or disruption
<br>> <a href="http://p.sf.net/sfu/oracle-sfdevnl" target="_top" rel="nofollow" link="external">http://p.sf.net/sfu/oracle-sfdevnl</a><br>> _______________________________________________
<br>> gstreamer-devel mailing list
<br>> [hidden email]
<br>> <a href="https://lists.sourceforge.net/lists/listinfo/gstreamer-devel" target="_top" rel="nofollow" link="external">https://lists.sourceforge.net/lists/listinfo/gstreamer-devel</a><br>>
<br>>
<br>> ________________________________
<br>> View message @
<br>> <a href="http://gstreamer-devel.966125.n4.nabble.com/Play-audio-from-a-memory-buffer-tp3173448p3174884.html?by-user=t" target="_top" rel="nofollow" link="external">http://gstreamer-devel.966125.n4.nabble.com/Play-audio-from-a-memory-buffer-tp3173448p3174884.html</a><br>> To unsubscribe from Play audio from a memory buffer?, click here.
<br></div>
<br><hr align="left" width="300">
View this message in context: <a href="http://gstreamer-devel.966125.n4.nabble.com/Play-audio-from-a-memory-buffer-tp3173448p3174994.html">Re: Play audio from a memory buffer?</a><br>
Sent from the <a href="http://gstreamer-devel.966125.n4.nabble.com/">GStreamer-devel mailing list archive</a> at Nabble.com.<br>