Example #1
0
static GstFlowReturn
vorbis_parse_drain_queue_prematurely (GstVorbisParse * parse)
{
    GstFlowReturn ret = GST_FLOW_OK;
    gint64 granulepos = MAX (parse->prev_granulepos, 0);

    /* got an EOS event, make sure to push out any buffers that were in the queue
     * -- won't normally be the case, but this catches the
     * didn't-get-a-granulepos-on-the-last-packet case. Assuming a continuous
     * stream. */

    /* if we got EOS before any buffers came, go ahead and push the other events
     * first */
    vorbis_parse_drain_event_queue (parse);

    while (!g_queue_is_empty (parse->buffer_queue)) {
        GstBuffer *buf;

        buf = GST_BUFFER_CAST (g_queue_pop_head (parse->buffer_queue));

        granulepos += GST_BUFFER_OFFSET (buf);
        ret = vorbis_parse_push_buffer (parse, buf, granulepos);

        if (ret != GST_FLOW_OK)
            goto done;
    }

    parse->prev_granulepos = granulepos;

done:
    return ret;
}
Example #2
0
static void
vorbis_parse_push_headers (GstVorbisParse * parse)
{
    /* mark and put on caps */
    GstCaps *caps;
    GstBuffer *outbuf, *outbuf1, *outbuf2, *outbuf3;
    ogg_packet packet;

    /* get the headers into the caps, passing them to vorbis as we go */
    caps = gst_caps_make_writable (gst_pad_get_caps (parse->srcpad));
    vorbis_parse_set_header_on_caps (parse, caps);
    GST_DEBUG_OBJECT (parse, "here are the caps: %" GST_PTR_FORMAT, caps);
    gst_pad_set_caps (parse->srcpad, caps);
    gst_caps_unref (caps);

    outbuf = GST_BUFFER_CAST (parse->streamheader->data);
    packet.packet = GST_BUFFER_DATA (outbuf);
    packet.bytes = GST_BUFFER_SIZE (outbuf);
    packet.granulepos = GST_BUFFER_OFFSET_END (outbuf);
    packet.packetno = 1;
    packet.e_o_s = 0;
    packet.b_o_s = 1;
    vorbis_synthesis_headerin (&parse->vi, &parse->vc, &packet);
    parse->sample_rate = parse->vi.rate;
    outbuf1 = outbuf;

    outbuf = GST_BUFFER_CAST (parse->streamheader->next->data);
    packet.packet = GST_BUFFER_DATA (outbuf);
    packet.bytes = GST_BUFFER_SIZE (outbuf);
    packet.granulepos = GST_BUFFER_OFFSET_END (outbuf);
    packet.packetno = 2;
    packet.e_o_s = 0;
    packet.b_o_s = 0;
    vorbis_synthesis_headerin (&parse->vi, &parse->vc, &packet);
    outbuf2 = outbuf;

    outbuf = GST_BUFFER_CAST (parse->streamheader->next->next->data);
    packet.packet = GST_BUFFER_DATA (outbuf);
    packet.bytes = GST_BUFFER_SIZE (outbuf);
    packet.granulepos = GST_BUFFER_OFFSET_END (outbuf);
    packet.packetno = 3;
    packet.e_o_s = 0;
    packet.b_o_s = 0;
    vorbis_synthesis_headerin (&parse->vi, &parse->vc, &packet);
    outbuf3 = outbuf;

    /* first process queued events */
    vorbis_parse_drain_event_queue (parse);

    /* push out buffers, ignoring return value... */
    outbuf1 = gst_buffer_make_metadata_writable (outbuf1);
    gst_buffer_set_caps (outbuf1, GST_PAD_CAPS (parse->srcpad));
    gst_pad_push (parse->srcpad, outbuf1);
    outbuf2 = gst_buffer_make_metadata_writable (outbuf2);
    gst_buffer_set_caps (outbuf2, GST_PAD_CAPS (parse->srcpad));
    gst_pad_push (parse->srcpad, outbuf2);
    outbuf3 = gst_buffer_make_metadata_writable (outbuf3);
    gst_buffer_set_caps (outbuf3, GST_PAD_CAPS (parse->srcpad));
    gst_pad_push (parse->srcpad, outbuf3);

    g_list_free (parse->streamheader);
    parse->streamheader = NULL;
}
static void
vorbis_parse_push_headers (GstVorbisParse * parse)
{
  /* mark and put on caps */
  GstCaps *caps;
  GstBuffer *outbuf, *outbuf1, *outbuf2, *outbuf3;
  ogg_packet packet;
  GstMapInfo map;

  outbuf = GST_BUFFER_CAST (parse->streamheader->data);
  gst_buffer_map (outbuf, &map, GST_MAP_READ);
  packet.packet = map.data;
  packet.bytes = map.size;
  packet.granulepos = GST_BUFFER_OFFSET_END (outbuf);
  packet.packetno = 1;
  packet.e_o_s = 0;
  packet.b_o_s = 1;
  vorbis_synthesis_headerin (&parse->vi, &parse->vc, &packet);
  gst_buffer_unmap (outbuf, &map);
  parse->sample_rate = parse->vi.rate;
  parse->channels = parse->vi.channels;
  outbuf1 = outbuf;

  outbuf = GST_BUFFER_CAST (parse->streamheader->next->data);
  gst_buffer_map (outbuf, &map, GST_MAP_READ);
  packet.packet = map.data;
  packet.bytes = map.size;
  packet.granulepos = GST_BUFFER_OFFSET_END (outbuf);
  packet.packetno = 2;
  packet.e_o_s = 0;
  packet.b_o_s = 0;
  vorbis_synthesis_headerin (&parse->vi, &parse->vc, &packet);
  gst_buffer_unmap (outbuf, &map);
  outbuf2 = outbuf;

  outbuf = GST_BUFFER_CAST (parse->streamheader->next->next->data);
  gst_buffer_map (outbuf, &map, GST_MAP_READ);
  packet.packet = map.data;
  packet.bytes = map.size;
  packet.granulepos = GST_BUFFER_OFFSET_END (outbuf);
  packet.packetno = 3;
  packet.e_o_s = 0;
  packet.b_o_s = 0;
  vorbis_synthesis_headerin (&parse->vi, &parse->vc, &packet);
  gst_buffer_unmap (outbuf, &map);
  outbuf3 = outbuf;

  /* get the headers into the caps, passing them to vorbis as we go */
  caps = gst_caps_new_simple ("audio/x-vorbis",
      "rate", G_TYPE_INT, parse->sample_rate,
      "channels", G_TYPE_INT, parse->channels, NULL);
  vorbis_parse_set_header_on_caps (parse, caps);
  GST_DEBUG_OBJECT (parse, "here are the caps: %" GST_PTR_FORMAT, caps);
  gst_pad_set_caps (parse->srcpad, caps);
  gst_caps_unref (caps);

  /* first process queued events */
  vorbis_parse_drain_event_queue (parse);

  /* push out buffers, ignoring return value... */
  gst_pad_push (parse->srcpad, outbuf1);
  gst_pad_push (parse->srcpad, outbuf2);
  gst_pad_push (parse->srcpad, outbuf3);

  g_list_free (parse->streamheader);
  parse->streamheader = NULL;
}