Ejemplo n.º 1
0
/* from the given two data buffers, create two streamheader buffers and
 * some caps that match it, and store them in the given pointers
 * returns  one ref to each of the buffers and the caps */
static void
gst_multisocketsink_create_streamheader (const gchar * data1,
    const gchar * data2, GstBuffer ** hbuf1, GstBuffer ** hbuf2,
    GstCaps ** caps)
{
  GstBuffer *buf;
  GValue array = { 0 };
  GValue value = { 0 };
  GstStructure *structure;
  guint size1 = strlen (data1);
  guint size2 = strlen (data2);

  fail_if (hbuf1 == NULL);
  fail_if (hbuf2 == NULL);
  fail_if (caps == NULL);

  /* create caps with streamheader, set the caps, and push the HEADER
   * buffers */
  *hbuf1 = gst_buffer_new_and_alloc (size1);
  GST_BUFFER_FLAG_SET (*hbuf1, GST_BUFFER_FLAG_HEADER);
  gst_buffer_fill (*hbuf1, 0, data1, size1);
  *hbuf2 = gst_buffer_new_and_alloc (size2);
  GST_BUFFER_FLAG_SET (*hbuf2, GST_BUFFER_FLAG_HEADER);
  gst_buffer_fill (*hbuf2, 0, data2, size2);

  g_value_init (&array, GST_TYPE_ARRAY);

  g_value_init (&value, GST_TYPE_BUFFER);
  /* we take a copy, set it on the array (which refs it), then unref our copy */
  buf = gst_buffer_copy (*hbuf1);
  gst_value_set_buffer (&value, buf);
  ASSERT_BUFFER_REFCOUNT (buf, "copied buffer", 2);
  gst_buffer_unref (buf);
  gst_value_array_append_value (&array, &value);
  g_value_unset (&value);

  g_value_init (&value, GST_TYPE_BUFFER);
  buf = gst_buffer_copy (*hbuf2);
  gst_value_set_buffer (&value, buf);
  ASSERT_BUFFER_REFCOUNT (buf, "copied buffer", 2);
  gst_buffer_unref (buf);
  gst_value_array_append_value (&array, &value);
  g_value_unset (&value);

  *caps = gst_caps_from_string ("application/x-gst-check");
  structure = gst_caps_get_structure (*caps, 0);

  gst_structure_set_value (structure, "streamheader", &array);
  g_value_unset (&array);
  ASSERT_CAPS_REFCOUNT (*caps, "streamheader caps", 1);

  /* we want to keep them around for the tests */
  gst_buffer_ref (*hbuf1);
  gst_buffer_ref (*hbuf2);

  GST_DEBUG ("created streamheader caps %p %" GST_PTR_FORMAT, *caps, *caps);
}
Ejemplo n.º 2
0
static GstFlowReturn
gst_videosplitter_chain (GstPad * pad, GstBuffer * buf)
{
  GstVideoSplitter *videosplitter;
  GstFlowReturn ret = GST_FLOW_OK;
  GstBuffer *outbuf1 = NULL;
  GstBuffer *outbuf2 = NULL;
  gint width, height;	
 
  
  printf("\n==========In gst_videosplitter_chain==========\n");
  videosplitter = GST_VIDEOSPLITTER (gst_pad_get_parent (pad));
  width = videosplitter->width;
  height = videosplitter->height;


  outbuf1 = gst_buffer_copy(buf); //Create outbuf1 as a copy of buf.
  gst_buffer_copy_metadata(outbuf1, buf, GST_BUFFER_COPY_ALL); 
  //GST_BUFFER_TIMESTAMP(outbuf1) = GST_CLOCK_TIME_NONE;//timestampOut;

  printf("\n==========Pushing to src1==========\n");
  ret = gst_pad_push (videosplitter->srcpad1, outbuf1);
  if( ret != GST_FLOW_OK) printf("\n===========Push Failed============\n");
  if(ret != GST_FLOW_OK) goto push_failed;
  printf("\n==========Push successful==========\n");


 if(videosplitter->pushsrc2) //Create outbuf2 and push it onto srcpad2 only if videosplitter->pushsrc2 is TRUE.
 {
	  outbuf2 = gst_buffer_copy(buf); //Create outbuf2 as a copy of buf
	  gst_buffer_copy_metadata(outbuf2, buf, GST_BUFFER_COPY_ALL);
	  //GST_BUFFER_TIMESTAMP(outbuf2) = GST_CLOCK_TIME_NONE;//timestampOut;

	  printf("\n==========Pushing to src2==========\n");
	  ret = gst_pad_push (videosplitter->srcpad2, outbuf2);
	  printf("\n==========Push successful==========\n");  
 }

push_failed:
  if(ret != GST_FLOW_OK)
  {
	  GST_DEBUG ("push() failed, flow = %s", gst_flow_get_name (ret));
  }

  
  gst_buffer_unref (buf);
  gst_object_unref (videosplitter);
 
  return ret;
}
Ejemplo n.º 3
0
static GstCaps *
theora_set_header_on_caps (GstCaps * caps, GstBuffer * buf1,
    GstBuffer * buf2, GstBuffer * buf3)
{
  GstStructure *structure;
  GValue array = { 0 };
  GValue value = { 0 };

  caps = gst_caps_make_writable (caps);
  structure = gst_caps_get_structure (caps, 0);

  /* mark buffers */
  GST_BUFFER_FLAG_SET (buf1, GST_BUFFER_FLAG_IN_CAPS);
  GST_BUFFER_FLAG_SET (buf2, GST_BUFFER_FLAG_IN_CAPS);
  GST_BUFFER_FLAG_SET (buf3, GST_BUFFER_FLAG_IN_CAPS);

  /* Copy buffers, because we can't use the originals -
   * it creates a circular refcount with the caps<->buffers */
  buf1 = gst_buffer_copy (buf1);
  buf2 = gst_buffer_copy (buf2);
  buf3 = gst_buffer_copy (buf3);

  /* put copies of the buffers in a fixed list */
  g_value_init (&array, GST_TYPE_ARRAY);

  g_value_init (&value, GST_TYPE_BUFFER);
  gst_value_set_buffer (&value, buf1);
  gst_value_array_append_value (&array, &value);
  g_value_unset (&value);

  g_value_init (&value, GST_TYPE_BUFFER);
  gst_value_set_buffer (&value, buf2);
  gst_value_array_append_value (&array, &value);
  g_value_unset (&value);

  g_value_init (&value, GST_TYPE_BUFFER);
  gst_value_set_buffer (&value, buf3);
  gst_value_array_append_value (&array, &value);
  g_value_unset (&value);

  gst_structure_set_value (structure, "streamheader", &array);
  g_value_unset (&array);

  /* Unref our copies */
  gst_buffer_unref (buf1);
  gst_buffer_unref (buf2);
  gst_buffer_unref (buf3);

  return caps;
}
Ejemplo n.º 4
0
static GstFlowReturn
gst_nle_source_push_still_picture (GstNleSource * nlesrc, GstNleSrcItem * item,
    GstBuffer * buf)
{
  GstCaps *bcaps, *ncaps;
  guint64 buf_dur;
  gint i, n_bufs;
  GstFlowReturn ret = GST_FLOW_OK;

  buf_dur = GST_SECOND * nlesrc->fps_d / nlesrc->fps_n;
  n_bufs = item->duration / buf_dur;

  bcaps = gst_buffer_get_caps (buf);
  ncaps = gst_caps_make_writable (bcaps);
  gst_caps_set_simple (ncaps, "pixel-aspect-ratio", GST_TYPE_FRACTION,
      1, 1, NULL);
  gst_buffer_set_caps (buf, ncaps);
  gst_caps_unref (ncaps);

  nlesrc->video_seek_done = TRUE;
  for (i = 0; i < n_bufs; i++) {
    GstBuffer *new_buf;

    new_buf = gst_buffer_copy (buf);
    GST_BUFFER_TIMESTAMP (new_buf) = item->start + buf_dur * i;
    GST_BUFFER_DURATION (new_buf) = buf_dur;
    ret = gst_nle_source_push_buffer (nlesrc, new_buf, FALSE);
    if (ret <= GST_FLOW_UNEXPECTED) {
      break;
    }
  }

  gst_buffer_unref (buf);
  return ret;
}
Ejemplo n.º 5
0
static GstFlowReturn
gst_ofa_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
{
  GstOFA *ofa = GST_OFA (trans);
  GstAudioFilter *ofa_filter = GST_AUDIO_FILTER (ofa);
  guint64 nframes;
  GstClockTime duration;
  gint rate = ofa_filter->format.rate;
  gint channels = ofa_filter->format.channels;

  g_return_val_if_fail (rate > 0 && channels > 0, GST_FLOW_NOT_NEGOTIATED);

  if (!ofa->record)
    return GST_FLOW_OK;

  gst_adapter_push (ofa->adapter, gst_buffer_copy (buf));

  nframes = gst_adapter_available (ofa->adapter) / (channels * 2);
  duration = GST_FRAMES_TO_CLOCK_TIME (nframes, rate);

  if (duration >= 135 * GST_SECOND && ofa->fingerprint == NULL)
    create_fingerprint (ofa);

  return GST_FLOW_OK;
}
Ejemplo n.º 6
0
static void
new_packet_common_init (MpegTsMux * mux, GstBuffer * buf, guint8 * data,
    guint len)
{
  /* Packets should be at least 188 bytes, but check anyway */
  g_return_if_fail (len >= 2);

  if (!mux->streamheader_sent) {
    guint pid = ((data[1] & 0x1f) << 8) | data[2];
    /* if it's a PAT or a PMT */
    if (pid == 0x00 || (pid >= TSMUX_START_PMT_PID && pid < TSMUX_START_ES_PID)) {
      mux->streamheader =
          g_list_append (mux->streamheader, gst_buffer_copy (buf));
    } else if (mux->streamheader) {
      mpegtsdemux_set_header_on_caps (mux);
      mux->streamheader_sent = TRUE;
    }
  }

  /* Set the caps on the buffer only after possibly setting the stream headers
   * into the pad caps above */
  gst_buffer_set_caps (buf, GST_PAD_CAPS (mux->srcpad));

  if (mux->is_delta) {
    GST_LOG_OBJECT (mux, "marking as delta unit");
    GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
  } else {
    GST_DEBUG_OBJECT (mux, "marking as non-delta unit");
    mux->is_delta = TRUE;
  }
}
Ejemplo n.º 7
0
GstBuffer *
mpegpsmux_prepare_aac (GstBuffer * buf, MpegPsPadData * data, MpegPsMux * mux)
{
  GstBuffer *out_buf;
  GstMemory *mem;
  gsize out_size;
  guint8 *adts_header, codec_data[2];
  guint8 rate_idx = 0, channels = 0, obj_type = 0;

  GST_DEBUG_OBJECT (mux, "Preparing AAC buffer for output");

  adts_header = g_malloc0 (7);

  /* We want the same data and metadata, and then prepend some bytes */
  out_buf = gst_buffer_copy (buf);
  out_size = gst_buffer_get_size (buf) + 7;

  gst_buffer_extract (data->codec_data, 0, codec_data, 2);

  /* Generate ADTS header */
  obj_type = (codec_data[0] & 0xC) >> 2;
  obj_type++;
  rate_idx = (codec_data[0] & 0x3) << 1;
  rate_idx |= (codec_data[1] & 0x80) >> 7;
  channels = (codec_data[1] & 0x78) >> 3;
  GST_DEBUG_OBJECT (mux, "Rate index %u, channels %u, object type %u", rate_idx,
      channels, obj_type);
  /* Sync point over a full byte */
  adts_header[0] = 0xFF;
  /* Sync point continued over first 4 bits + static 4 bits
   * (ID, layer, protection)*/
  adts_header[1] = 0xF1;
  /* Object type over first 2 bits */
  adts_header[2] = obj_type << 6;
  /* rate index over next 4 bits */
  adts_header[2] |= (rate_idx << 2);
  /* channels over last 2 bits */
  adts_header[2] |= (channels & 0x4) >> 2;
  /* channels continued over next 2 bits + 4 bits at zero */
  adts_header[3] = (channels & 0x3) << 6;
  /* frame size over last 2 bits */
  adts_header[3] |= (gst_buffer_get_size (out_buf) & 0x1800) >> 11;
  /* frame size continued over full byte */
  adts_header[4] = (out_size & 0x1FF8) >> 3;
  /* frame size continued first 3 bits */
  adts_header[5] = (out_size & 0x7) << 5;
  /* buffer fullness (0x7FF for VBR) over 5 last bits */
  adts_header[5] |= 0x1F;
  /* buffer fullness (0x7FF for VBR) continued over 6 first bits + 2 zeros for
   * number of raw data blocks */
  adts_header[6] = 0xFC;

  /* Prepend ADTS header */
  mem = gst_memory_new_wrapped (0, adts_header, 7, 0, 7, adts_header, g_free);
  gst_buffer_prepend_memory (out_buf, mem);

  return out_buf;
}
Ejemplo n.º 8
0
/* Set a copy of these buffers as 'streamheader' on the caps.
 * We need a copy to avoid these buffers ending up with (indirect) refs on
 * themselves
 */
static GstCaps *
gst_vorbis_enc_set_header_on_caps (GstCaps * caps, GstBuffer * buf1,
    GstBuffer * buf2, GstBuffer * buf3)
{
  GstBuffer *buf;
  GstStructure *structure;
  GValue array = { 0 };
  GValue value = { 0 };

  caps = gst_caps_make_writable (caps);
  structure = gst_caps_get_structure (caps, 0);

  /* mark buffers */
  GST_BUFFER_FLAG_SET (buf1, GST_BUFFER_FLAG_IN_CAPS);
  GST_BUFFER_FLAG_SET (buf2, GST_BUFFER_FLAG_IN_CAPS);
  GST_BUFFER_FLAG_SET (buf3, GST_BUFFER_FLAG_IN_CAPS);

  /* put buffers in a fixed list */
  g_value_init (&array, GST_TYPE_ARRAY);
  g_value_init (&value, GST_TYPE_BUFFER);
  buf = gst_buffer_copy (buf1);
  gst_value_set_buffer (&value, buf);
  gst_buffer_unref (buf);
  gst_value_array_append_value (&array, &value);
  g_value_unset (&value);
  g_value_init (&value, GST_TYPE_BUFFER);
  buf = gst_buffer_copy (buf2);
  gst_value_set_buffer (&value, buf);
  gst_buffer_unref (buf);
  gst_value_array_append_value (&array, &value);
  g_value_unset (&value);
  g_value_init (&value, GST_TYPE_BUFFER);
  buf = gst_buffer_copy (buf3);
  gst_value_set_buffer (&value, buf);
  gst_buffer_unref (buf);
  gst_value_array_append_value (&array, &value);
  gst_structure_set_value (structure, "streamheader", &array);
  g_value_unset (&value);
  g_value_unset (&array);

  return caps;
}
Ejemplo n.º 9
0
static GstCaps *
gst_cmml_enc_set_header_on_caps (GstCmmlEnc * enc, GstCaps * caps,
    GstBuffer * ident, GstBuffer * preamble, GstBuffer * head)
{
  GValue array = { 0 };
  GValue value = { 0 };
  GstStructure *structure;
  GstBuffer *buffer;

  caps = gst_caps_make_writable (caps);
  structure = gst_caps_get_structure (caps, 0);

  g_value_init (&array, GST_TYPE_ARRAY);
  g_value_init (&value, GST_TYPE_BUFFER);

  /* Make copies of header buffers to avoid circular references */
  buffer = gst_buffer_copy (ident);
  gst_value_set_buffer (&value, buffer);
  gst_value_array_append_value (&array, &value);
  gst_buffer_unref (buffer);

  buffer = gst_buffer_copy (preamble);
  gst_value_set_buffer (&value, buffer);
  gst_value_array_append_value (&array, &value);
  gst_buffer_unref (buffer);

  buffer = gst_buffer_copy (head);
  gst_value_set_buffer (&value, buffer);
  gst_value_array_append_value (&array, &value);
  gst_buffer_unref (buffer);

  GST_BUFFER_FLAG_SET (ident, GST_BUFFER_FLAG_IN_CAPS);
  GST_BUFFER_FLAG_SET (preamble, GST_BUFFER_FLAG_IN_CAPS);
  GST_BUFFER_FLAG_SET (head, GST_BUFFER_FLAG_IN_CAPS);

  gst_structure_set_value (structure, "streamheader", &array);

  g_value_unset (&value);
  g_value_unset (&array);

  return caps;
}
Ejemplo n.º 10
0
static GstPadProbeReturn
sinkpad_enqueue_buffer (GstPad * pad, GstPadProbeInfo * info, gpointer data)
{
  GQueue *queue = (GQueue *) data;
  GstBuffer *buf = GST_PAD_PROBE_INFO_BUFFER (info);

  /* enqueue a copy for being compared later */
  g_queue_push_tail (queue, gst_buffer_copy (buf));

  return GST_PAD_PROBE_OK;
}
static gboolean webKitMediaClearKeyDecryptorHandleKeyResponse(WebKitMediaCommonEncryptionDecrypt* self, GstEvent* event)
{
    WebKitMediaClearKeyDecryptPrivate* priv = WEBKIT_MEDIA_CK_DECRYPT_GET_PRIVATE(WEBKIT_MEDIA_CK_DECRYPT(self));
    const GstStructure* structure = gst_event_get_structure(event);

    if (!gst_structure_has_name(structure, "drm-cipher"))
        return FALSE;

    const GValue* value = gst_structure_get_value(structure, "key");
    priv->key.clear();
    priv->key = adoptGRef(gst_buffer_copy(gst_value_get_buffer(value)));
    return TRUE;
}
static void
gst_ogg_parse_append_header (GValue * array, GstBuffer * buf)
{
  GValue value = { 0 };
  /* We require a copy to avoid circular refcounts */
  GstBuffer *buffer = gst_buffer_copy (buf);

  GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_HEADER);

  g_value_init (&value, GST_TYPE_BUFFER);
  gst_value_set_buffer (&value, buffer);
  gst_value_array_append_value (array, &value);
  g_value_unset (&value);

}
Ejemplo n.º 13
0
static GstFlowReturn
gst_y4m_encode_handle_frame (GstVideoEncoder * encoder,
    GstVideoCodecFrame * frame)
{
  GstY4mEncode *filter = GST_Y4M_ENCODE (encoder);
  GstClockTime timestamp;

  /* check we got some decent info from caps */
  if (GST_VIDEO_INFO_FORMAT (&filter->info) == GST_VIDEO_FORMAT_UNKNOWN)
    goto not_negotiated;

  timestamp = GST_BUFFER_TIMESTAMP (frame->input_buffer);

  if (G_UNLIKELY (!filter->header)) {
    gboolean tff = FALSE;

    if (GST_VIDEO_INFO_IS_INTERLACED (&filter->info)) {
      tff =
          GST_BUFFER_FLAG_IS_SET (frame->input_buffer,
          GST_VIDEO_BUFFER_FLAG_TFF);
    }
    frame->output_buffer = gst_y4m_encode_get_stream_header (filter, tff);
    filter->header = TRUE;
    frame->output_buffer =
        gst_buffer_append (frame->output_buffer,
        gst_y4m_encode_get_frame_header (filter));
  } else {
    frame->output_buffer = gst_y4m_encode_get_frame_header (filter);
  }

  frame->output_buffer =
      gst_buffer_append (frame->output_buffer,
      gst_buffer_copy (frame->input_buffer));

  /* decorate */
  frame->output_buffer = gst_buffer_make_writable (frame->output_buffer);
  GST_BUFFER_TIMESTAMP (frame->output_buffer) = timestamp;

  return gst_video_encoder_finish_frame (encoder, frame);

not_negotiated:
  {
    GST_ELEMENT_ERROR (filter, CORE, NEGOTIATION, (NULL),
        ("format wasn't negotiated"));

    return GST_FLOW_NOT_NEGOTIATED;
  }
}
Ejemplo n.º 14
0
static GstBuffer *
gst_slot_buffer_new (GstTSCache * cache, Slot * slot)
{
  SlotMeta *meta;

  GstBuffer *buffer = gst_buffer_copy (slot->buffer);

  meta = (SlotMeta *) gst_buffer_add_meta (buffer, SLOT_META_INFO, NULL);
  meta->cache = gst_ts_cache_ref (cache);
  meta->slot = slot;

  GST_BUFFER_OFFSET (buffer) = GST_BUFFER_OFFSET (slot->buffer);
  GST_BUFFER_OFFSET_END (buffer) = GST_BUFFER_OFFSET (buffer) + slot->size;

  return buffer;
}
Ejemplo n.º 15
0
struct RCMusicMetaData *rc_cue_get_metadata(RCCueData *cue_data,
    gint track_num, struct RCMusicMetaData *cue_mmd)
{
    RCMusicMetaData *mmd = NULL;
    RCCueTrack *track = NULL;
    gboolean empty_flag = FALSE;
    if(cue_data==NULL) return NULL;
    if(cue_mmd==NULL)
    {
        if(cue_data->file==NULL) return NULL;
        cue_mmd = rc_tag_read_metadata(cue_data->file);
        if(cue_mmd==NULL) return NULL;
        empty_flag = TRUE;
    }
    if(track_num<0 || track_num>=cue_data->length) return NULL;
    track = cue_data->track + track_num;
    mmd = g_new0(RCMusicMetaData, 1);
    if(track->title!=NULL)
        mmd->title = g_strdup(track->title);
    else
        mmd->title = g_strdup_printf("Track %d", track_num);
    if(track->performer!=NULL)
        mmd->artist = g_strdup(track->performer);
    if(cue_data->title!=NULL)
        mmd->album = g_strdup(cue_data->title);
    mmd->tracknum = track_num + 1;
    if(track_num+1!=cue_data->length)
        mmd->length = track[1].time1 - track->time1;
    else
        mmd->length = cue_mmd->length - track->time1;
    if(cue_data->file!=NULL)
        mmd->uri = g_strdup_printf("%s:%d", cue_data->file, track_num+1);
    else
        mmd->uri = g_strdup_printf("%s:%d", cue_mmd->uri, track_num+1);
    if(cue_mmd->file_type!=NULL)
        mmd->file_type = g_strdup(cue_mmd->file_type);
    if(cue_mmd->comment!=NULL)
        mmd->comment = g_strdup(cue_mmd->comment);
    mmd->bitrate = cue_mmd->bitrate;
    mmd->samplerate = cue_mmd->samplerate;
    mmd->channels = cue_mmd->channels;
    if(cue_mmd->image!=NULL)
        mmd->image = gst_buffer_copy(cue_mmd->image);
    if(empty_flag) rc_tag_free(cue_mmd);
    mmd->audio_flag = TRUE;
    return mmd;
}
Ejemplo n.º 16
0
void test_non_ok_flow()
{
  GstElement *videorate;
  GstClockTime ts;
  GstBuffer *buf;
  GstCaps *caps;

  videorate = setup_videorate ();
  fail_unless (gst_element_set_state (videorate,
          GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
      "could not set to playing");

  buf = gst_buffer_new_and_alloc (4);
  memset (GST_BUFFER_DATA (buf), 0, 4);
  caps = gst_caps_from_string (VIDEO_CAPS_STRING);
  gst_buffer_set_caps (buf, caps);
  gst_caps_unref (caps);
  ASSERT_BUFFER_REFCOUNT (buf, "inbuffer", 1);

  /* push a few 'normal' buffers */
  for (ts = 0; ts < 100 * GST_SECOND; ts += GST_SECOND / 33) {
    GstBuffer *inbuf;

    inbuf = gst_buffer_copy (buf);
    GST_BUFFER_TIMESTAMP (inbuf) = ts;

    fail_unless_equals_int (gst_pad_push (mysrcpad, inbuf), GST_FLOW_OK);
  }

  /* we should have buffers according to the output framerate of 25/1 */
  fail_unless_equals_int (g_list_length (buffers), 100 * 25);

  /* now deactivate pad so we get a WRONG_STATE flow return */
  gst_pad_set_active (mysinkpad, FALSE);

  /* push buffer on deactivated pad */
  fail_unless (gst_buffer_is_metadata_writable (buf));
  GST_BUFFER_TIMESTAMP (buf) = ts;

  /* pushing gives away our reference */
  fail_unless_equals_int (gst_pad_push (mysrcpad, buf), GST_FLOW_WRONG_STATE);

  /* cleanup */
  cleanup_videorate (videorate);
  std_log(LOG_FILENAME_LINE, "Test Successful");
  create_xml(0);
}
Ejemplo n.º 17
0
static gboolean
gst_rtp_mp4v_pay_setcaps (GstBaseRTPPayload * payload, GstCaps * caps)
{
  GstRtpMP4VPay *rtpmp4vpay;
  GstStructure *structure;
  const GValue *codec_data;

  rtpmp4vpay = GST_RTP_MP4V_PAY (payload);

  gst_basertppayload_set_options (payload, "video", TRUE, "MP4V-ES",
      rtpmp4vpay->rate);

  structure = gst_caps_get_structure (caps, 0);
  codec_data = gst_structure_get_value (structure, "codec_data");
  if (codec_data) {
    GST_LOG_OBJECT (rtpmp4vpay, "got codec_data");
    if (G_VALUE_TYPE (codec_data) == GST_TYPE_BUFFER) {
      GstBuffer *buffer;
      guint8 *data;
      guint size;

      buffer = gst_value_get_buffer (codec_data);

      data = GST_BUFFER_DATA (buffer);
      size = GST_BUFFER_SIZE (buffer);

      if (size < 5)
        goto done;

      rtpmp4vpay->profile = data[4];
      GST_LOG_OBJECT (rtpmp4vpay, "configuring codec_data, profile %d",
          data[4]);

      if (rtpmp4vpay->config)
        gst_buffer_unref (rtpmp4vpay->config);
      rtpmp4vpay->config = gst_buffer_copy (buffer);
      gst_rtp_mp4v_pay_new_caps (rtpmp4vpay);
    }
  }

done:
  return TRUE;
}
Ejemplo n.º 18
0
/*
 * _gst_caps_set_buffer_array:
 * @caps: (transfer full): a #GstCaps
 * @field: field in caps to set
 * @buf: header buffers
 *
 * Adds given buffers to an array of buffers set as the given @field
 * on the given @caps.  List of buffer arguments must be NULL-terminated.
 *
 * Returns: (transfer full): input caps with a streamheader field added, or NULL
 *     if some error occurred
 */
static GstCaps *
_gst_caps_set_buffer_array (GstCaps * caps, const gchar * field,
    GstBuffer * buf, ...)
{
  GstStructure *structure = NULL;
  va_list va;
  GValue array = { 0 };
  GValue value = { 0 };

  g_return_val_if_fail (caps != NULL, NULL);
  g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
  g_return_val_if_fail (field != NULL, NULL);

  caps = gst_caps_make_writable (caps);
  structure = gst_caps_get_structure (caps, 0);

  g_value_init (&array, GST_TYPE_ARRAY);

  va_start (va, buf);
  /* put buffers in a fixed list */
  while (buf) {
    g_assert (gst_buffer_is_writable (buf));

    /* mark buffer */
    GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_HEADER);

    g_value_init (&value, GST_TYPE_BUFFER);
    buf = gst_buffer_copy (buf);
    GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_HEADER);
    gst_value_set_buffer (&value, buf);
    gst_buffer_unref (buf);
    gst_value_array_append_value (&array, &value);
    g_value_unset (&value);

    buf = va_arg (va, GstBuffer *);
  }
  va_end (va);

  gst_structure_set_value (structure, field, &array);
  g_value_unset (&array);

  return caps;
}
Ejemplo n.º 19
0
/* Create a copy of @buffer_in having the RTP extension */
static GstBuffer *
create_extension_buffer (GstBuffer * buffer_in, gboolean clean_point,
    gboolean end_contiguous, gboolean discont, guint64 ntp_offset, guint8 cseq)
{
  GstBuffer *buffer_out;
  GstRTPBuffer rtpbuffer_out = GST_RTP_BUFFER_INIT;
  guint8 *data;
  guint8 flags = 0;

  buffer_out = gst_buffer_copy (buffer_in);

  fail_unless (gst_rtp_buffer_map (buffer_out, GST_MAP_READWRITE,
          &rtpbuffer_out));

  /* extension */
  fail_unless (gst_rtp_buffer_set_extension_data (&rtpbuffer_out, 0xABAC, 3));
  fail_unless (gst_rtp_buffer_get_extension (&rtpbuffer_out));
  fail_unless (gst_rtp_buffer_get_extension_data (&rtpbuffer_out, NULL,
          (gpointer) & data, NULL));

  /* NTP timestamp */
  GST_WRITE_UINT64_BE (data, convert_to_ntp (GST_BUFFER_PTS (buffer_in) +
          ntp_offset));

  /* C E D mbz */
  if (clean_point)
    flags |= (1 << 7);
  if (end_contiguous)
    flags |= (1 << 6);
  if (discont)
    flags |= (1 << 5);

  GST_WRITE_UINT8 (data + 8, flags);

  /* CSeq */
  GST_WRITE_UINT8 (data + 9, cseq);

  memset (data + 10, 0, 4);

  gst_rtp_buffer_unmap (&rtpbuffer_out);

  return buffer_out;
}
Ejemplo n.º 20
0
/* Duplicate and push given buffer many times to all input_pads */
static void
push_input_buffers (GList * input_pads, GstBuffer * buf, gint num_buffers)
{
  GstBuffer *buf_in = NULL;
  GList *l = input_pads;
  GstPad *input_pad;
  gint i = 0;

  while (l != NULL) {
    input_pad = l->data;
    GST_DEBUG_OBJECT (input_pad, "pushing %d buffers to %" GST_PTR_FORMAT,
        num_buffers, input_pad);
    for (i = 0; i < num_buffers; i++) {
      buf_in = gst_buffer_copy (buf);
      fail_unless (gst_pad_push (input_pad, buf_in) == GST_FLOW_OK,
          "pushing buffer failed");
    }
    l = g_list_next (l);
  }
}
Ejemplo n.º 21
0
GstCaps *
gst_kate_util_set_header_on_caps (GstElement * element, GstCaps * caps,
    GList * headers)
{
  GstStructure *structure;
  GValue array = { 0 };

  GST_LOG_OBJECT (element, "caps: %" GST_PTR_FORMAT, caps);

  if (G_UNLIKELY (!caps))
    return NULL;
  if (G_UNLIKELY (!headers))
    return NULL;

  caps = gst_caps_make_writable (caps);
  structure = gst_caps_get_structure (caps, 0);

  g_value_init (&array, GST_TYPE_ARRAY);

  while (headers) {
    GValue value = { 0 };
    GstBuffer *buffer = headers->data;
    g_assert (buffer);
    GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_IN_CAPS);
    g_value_init (&value, GST_TYPE_BUFFER);
    /* as in theoraenc, we need to copy to avoid circular references */
    buffer = gst_buffer_copy (buffer);
    gst_value_set_buffer (&value, buffer);
    gst_buffer_unref (buffer);
    gst_value_array_append_value (&array, &value);
    g_value_unset (&value);
    headers = headers->next;
  }

  gst_structure_set_value (structure, "streamheader", &array);
  g_value_unset (&array);
  GST_LOG_OBJECT (element, "here are the newly set caps: %" GST_PTR_FORMAT,
      caps);

  return caps;
}
Ejemplo n.º 22
0
static GstFlowReturn
gst_webrtc_echo_probe_transform_ip (GstBaseTransform * btrans,
    GstBuffer * buffer)
{
  GstWebrtcEchoProbe *self = GST_WEBRTC_ECHO_PROBE (btrans);
  GstBuffer *newbuf = NULL;

  GST_WEBRTC_ECHO_PROBE_LOCK (self);
  newbuf = gst_buffer_copy (buffer);
  /* Moves the buffer timestamp to be in Running time */
  GST_BUFFER_PTS (newbuf) = gst_segment_to_running_time (&btrans->segment,
      GST_FORMAT_TIME, GST_BUFFER_PTS (buffer));
  gst_adapter_push (self->adapter, newbuf);

  if (gst_adapter_available (self->adapter) > MAX_ADAPTER_SIZE)
    gst_adapter_flush (self->adapter,
        gst_adapter_available (self->adapter) - MAX_ADAPTER_SIZE);
  GST_WEBRTC_ECHO_PROBE_UNLOCK (self);

  return GST_FLOW_OK;
}
Ejemplo n.º 23
0
void rc_tag_set_playing_metadata(const RCMusicMetaData *mmd)
{
    if(playing_mmd.uri!=NULL) g_free(playing_mmd.uri);
    if(playing_mmd.image!=NULL) gst_buffer_unref(playing_mmd.image);
    if(playing_mmd.title!=NULL) g_free(playing_mmd.title);
    if(playing_mmd.artist!=NULL) g_free(playing_mmd.artist);
    if(playing_mmd.album!=NULL) g_free(playing_mmd.album);
    if(playing_mmd.comment!=NULL) g_free(playing_mmd.comment);
    if(playing_mmd.file_type!=NULL) g_free(playing_mmd.file_type);
    memcpy(&playing_mmd, mmd, sizeof(RCMusicMetaData));
    if(mmd->uri!=NULL)
        playing_mmd.uri = g_strdup(mmd->uri);
    else
        playing_mmd.uri = NULL;
    if(mmd->image!=NULL)
        playing_mmd.image = gst_buffer_copy(mmd->image);
    else
        playing_mmd.image = NULL;
    if(mmd->title!=NULL)
        playing_mmd.title = g_strdup(mmd->title);
    else
        playing_mmd.title = NULL;
    if(mmd->artist!=NULL)
        playing_mmd.artist = g_strdup(mmd->artist);
    else
        playing_mmd.artist = NULL;
    if(mmd->album!=NULL)
        playing_mmd.album = g_strdup(mmd->album);
    else
        playing_mmd.album = NULL;
    if(mmd->comment!=NULL)
        playing_mmd.comment = g_strdup(mmd->comment);
    else
        playing_mmd.comment = NULL;
    if(mmd->file_type!=NULL)
        playing_mmd.file_type = g_strdup(mmd->file_type);
    else
        playing_mmd.file_type = NULL;
}
Ejemplo n.º 24
0
static GstCaps *
theora_set_header_on_caps (GstCaps * caps, GList * buffers)
{
    GstStructure *structure;
    GValue array = { 0 };
    GValue value = { 0 };
    GstBuffer *buffer;
    GList *walk;

    caps = gst_caps_make_writable (caps);
    structure = gst_caps_get_structure (caps, 0);

    /* put copies of the buffers in a fixed list */
    g_value_init (&array, GST_TYPE_ARRAY);

    for (walk = buffers; walk; walk = walk->next) {
        buffer = walk->data;

        /* mark buffer */
        GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_HEADER);

        /* Copy buffer, because we can't use the original -
         * it creates a circular refcount with the caps<->buffers */
        buffer = gst_buffer_copy (buffer);

        g_value_init (&value, GST_TYPE_BUFFER);
        gst_value_set_buffer (&value, buffer);
        gst_value_array_append_value (&array, &value);
        g_value_unset (&value);

        /* Unref our copy */
        gst_buffer_unref (buffer);
    }

    gst_structure_set_value (structure, "streamheader", &array);
    g_value_unset (&array);

    return caps;
}
Ejemplo n.º 25
0
static GstFlowReturn
gst_v4lsrc_create (GstPushSrc * src, GstBuffer ** buf)
{
    GstV4lSrc *v4lsrc;
    gint num;

    v4lsrc = GST_V4LSRC (src);

    /* grab a frame from the device */
    if (!gst_v4lsrc_grab_frame (v4lsrc, &num))
        return GST_FLOW_ERROR;

    *buf = gst_v4lsrc_buffer_new (v4lsrc, num);

    if (v4lsrc->copy_mode) {
        GstBuffer *copy = gst_buffer_copy (*buf);

        gst_buffer_unref (*buf);
        *buf = copy;
    }

    return GST_FLOW_OK;
}
Ejemplo n.º 26
0
static GstFlowReturn
test_injector_chain (GstPad * pad, GstBuffer * buf)
{
  GstFlowReturn ret;
  GstPad *srcpad;

  srcpad = gst_element_get_pad (GST_ELEMENT (GST_PAD_PARENT (pad)), "src");

  /* since we're increasing timestamp/offsets, push this one first */
  GST_LOG (" passing buffer   [t=%" GST_TIME_FORMAT "-%" GST_TIME_FORMAT
      "], offset=%" G_GINT64_FORMAT ", offset_end=%" G_GINT64_FORMAT,
      GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
      GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf)),
      GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET_END (buf));

  gst_buffer_ref (buf);

  ret = gst_pad_push (srcpad, buf);

  if (g_random_double () < injector_inject_probability) {
    GstBuffer *ibuf;

    ibuf = gst_buffer_copy (buf);

    if (GST_BUFFER_OFFSET_IS_VALID (buf) &&
        GST_BUFFER_OFFSET_END_IS_VALID (buf)) {
      guint64 delta;

      delta = GST_BUFFER_OFFSET_END (buf) - GST_BUFFER_OFFSET (buf);
      GST_BUFFER_OFFSET (ibuf) += delta / 4;
      GST_BUFFER_OFFSET_END (ibuf) += delta / 4;
    } else {
      GST_BUFFER_OFFSET (ibuf) = GST_BUFFER_OFFSET_NONE;
      GST_BUFFER_OFFSET_END (ibuf) = GST_BUFFER_OFFSET_NONE;
    }

    if (GST_BUFFER_TIMESTAMP_IS_VALID (buf) &&
        GST_BUFFER_DURATION_IS_VALID (buf)) {
      GstClockTime delta;

      delta = GST_BUFFER_DURATION (buf);
      GST_BUFFER_TIMESTAMP (ibuf) += delta / 4;
    } else {
      GST_BUFFER_TIMESTAMP (ibuf) = GST_CLOCK_TIME_NONE;
      GST_BUFFER_DURATION (ibuf) = GST_CLOCK_TIME_NONE;
    }

    if (GST_BUFFER_TIMESTAMP_IS_VALID (ibuf) ||
        GST_BUFFER_OFFSET_IS_VALID (ibuf)) {
      GST_LOG ("injecting buffer [t=%" GST_TIME_FORMAT "-%" GST_TIME_FORMAT
          "], offset=%" G_GINT64_FORMAT ", offset_end=%" G_GINT64_FORMAT,
          GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (ibuf)),
          GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (ibuf) +
              GST_BUFFER_DURATION (ibuf)), GST_BUFFER_OFFSET (ibuf),
          GST_BUFFER_OFFSET_END (ibuf));

      if (gst_pad_push (srcpad, ibuf) != GST_FLOW_OK) {
        /* ignore return value */
      }
    } else {
      GST_WARNING ("couldn't inject buffer, no incoming timestamps or offsets");
      gst_buffer_unref (ibuf);
    }
  }

  gst_buffer_unref (buf);

  return ret;
}
Ejemplo n.º 27
0
static gboolean
new_packet_cb (guint8 * data, guint len, void *user_data, gint64 new_pcr)
{
  /* Called when the TsMux has prepared a packet for output. Return FALSE
   * on error */
  MpegTsMux *mux = (MpegTsMux *) user_data;
  GstBuffer *buf, *out_buf;
  GstFlowReturn ret;
  gfloat current_ts;
  gint64 m2ts_pcr, pcr_bytes, chunk_bytes;
  gint8 *temp_ptr;
  gint64 ts_rate;

  if (mux->m2ts_mode == TRUE) {
    /* Enters when the m2ts-mode is set true */
    buf = gst_buffer_new_and_alloc (M2TS_PACKET_LENGTH);
    if (mux->is_delta) {
      GST_LOG_OBJECT (mux, "marking as delta unit");
      GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
    } else {
      GST_DEBUG_OBJECT (mux, "marking as non-delta unit");
      mux->is_delta = TRUE;
    }
    if (G_UNLIKELY (buf == NULL)) {
      mux->last_flow_ret = GST_FLOW_ERROR;
      return FALSE;
    }
    gst_buffer_set_caps (buf, GST_PAD_CAPS (mux->srcpad));

    /* copies the ts data of 188 bytes to the m2ts buffer at an offset 
       of 4 bytes of timestamp  */
    memcpy (GST_BUFFER_DATA (buf) + 4, data, len);

    if (new_pcr >= 0) {
      /*when there is a pcr value in ts data */
      pcr_bytes = 0;
      if (mux->first_pcr) {
        /*Incase of first pcr */
        /*writing the 4  byte timestamp value */
        GST_WRITE_UINT32_BE (GST_BUFFER_DATA (buf), new_pcr);

        GST_LOG_OBJECT (mux, "Outputting a packet of length %d",
            M2TS_PACKET_LENGTH);
        ret = gst_pad_push (mux->srcpad, buf);
        if (G_UNLIKELY (ret != GST_FLOW_OK)) {
          mux->last_flow_ret = ret;
          return FALSE;
        }
        mux->first_pcr = FALSE;
        mux->previous_pcr = new_pcr;
        pcr_bytes = M2TS_PACKET_LENGTH;
      }
      chunk_bytes = gst_adapter_available (mux->adapter);

      if (G_UNLIKELY (chunk_bytes)) {
        /* calculate rate based on latest and previous pcr values */
        ts_rate = ((chunk_bytes * STANDARD_TIME_CLOCK) / (new_pcr -
                mux->previous_pcr));
        while (1) {
          /*loop till all the accumulated ts packets are transformed to 
             m2ts packets and pushed */
          current_ts = ((gfloat) mux->previous_pcr / STANDARD_TIME_CLOCK) +
              ((gfloat) pcr_bytes / ts_rate);
          m2ts_pcr = (((gint64) (STANDARD_TIME_CLOCK * current_ts / 300) &
                  TWO_POW_33_MINUS1) * 300) + ((gint64) (STANDARD_TIME_CLOCK *
                  current_ts) % 300);
          temp_ptr = (gint8 *) & m2ts_pcr;

          out_buf = gst_adapter_take_buffer (mux->adapter, M2TS_PACKET_LENGTH);
          if (G_UNLIKELY (!out_buf))
            break;
          gst_buffer_set_caps (out_buf, GST_PAD_CAPS (mux->srcpad));

          /*writing the 4  byte timestamp value */
          GST_WRITE_UINT32_BE (GST_BUFFER_DATA (out_buf), m2ts_pcr);

          GST_LOG_OBJECT (mux, "Outputting a packet of length %d",
              M2TS_PACKET_LENGTH);
          ret = gst_pad_push (mux->srcpad, out_buf);
          if (G_UNLIKELY (ret != GST_FLOW_OK)) {
            mux->last_flow_ret = ret;
            return FALSE;
          }
          pcr_bytes += M2TS_PACKET_LENGTH;
        }
        mux->previous_pcr = m2ts_pcr;
      }
    } else
      /* If theres no pcr in current ts packet then push the packet 
         to an adapter, which is used to create m2ts packets */
      gst_adapter_push (mux->adapter, buf);
  } else {
    /* In case of Normal Ts packets */
    GST_LOG_OBJECT (mux, "Outputting a packet of length %d", len);
    buf = gst_buffer_new_and_alloc (len);
    if (G_UNLIKELY (buf == NULL)) {
      mux->last_flow_ret = GST_FLOW_ERROR;
      return FALSE;
    }
    gst_buffer_set_caps (buf, GST_PAD_CAPS (mux->srcpad));

    memcpy (GST_BUFFER_DATA (buf), data, len);
    GST_BUFFER_TIMESTAMP (buf) = mux->last_ts;

    if (!mux->streamheader_sent) {
      guint pid = ((data[1] & 0x1f) << 8) | data[2];
      /* if it's a PAT or a PMT */
      if (pid == 0x00 ||
          (pid >= TSMUX_START_PMT_PID && pid < TSMUX_START_ES_PID)) {
        mux->streamheader =
            g_list_append (mux->streamheader, gst_buffer_copy (buf));
      } else if (mux->streamheader) {
        mpegtsdemux_set_header_on_caps (mux);
        mux->streamheader_sent = TRUE;
        /* don't unset the streamheaders by pushing old caps */
        gst_buffer_set_caps (buf, GST_PAD_CAPS (mux->srcpad));
      }
    }

    if (mux->is_delta) {
      GST_LOG_OBJECT (mux, "marking as delta unit");
      GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
    } else {
      GST_DEBUG_OBJECT (mux, "marking as non-delta unit");
      mux->is_delta = TRUE;
    }

    ret = gst_pad_push (mux->srcpad, buf);
    if (G_UNLIKELY (ret != GST_FLOW_OK)) {
      mux->last_flow_ret = ret;
      return FALSE;
    }
  }

  return TRUE;
}
Ejemplo n.º 28
0
/**
 * @brief Change the data in buffer with given axis.
 * @param self this pointer to GstTensorAggregator
 * @param outbuf buffer to be concatenated
 * @param info tensor info for one frame
 */
static void
gst_tensor_aggregator_concat (GstTensorAggregator * self, GstBuffer * outbuf,
    const GstTensorInfo * info)
{
  GstBuffer *srcbuf;
  GstMapInfo src_info, dest_info;
  guint f;
  gsize block_size;
  gsize src_idx, dest_idx;
  gsize frame_size;

  frame_size = gst_tensor_info_get_size (info);
  g_assert (frame_size > 0);

  srcbuf = gst_buffer_copy (outbuf);
  outbuf = gst_buffer_make_writable (outbuf);

  g_assert (gst_buffer_map (srcbuf, &src_info, GST_MAP_READ));
  g_assert (gst_buffer_map (outbuf, &dest_info, GST_MAP_WRITE));

  /**
   * Concatenate output buffer with given axis (frames-dim)
   * If frames-dim is equal to (NNS_TENSOR_RANK_LIMIT - 1), nothing to do.
   * (In this case, this function will not be called. See gst_tensor_aggregator_check_concat_axis ())
   ********************************************************************
   * Ex1) concatenate 2 frames with dimension 3:4:2:1
   ********************************************************************
   * frame 1
   *   [
   *     [ [1101 1102 1103] [1104 1105 1106] [1107 1108 1109] [1110 1111 1112] ]
   *     [ [1113 1114 1115] [1116 1117 1118] [1119 1120 1121] [1122 1123 1124] ]
   *   ]
   *
   * frame 2
   *   [
   *     [ [2101 2102 2103] [2104 2105 2106] [2107 2108 2109] [2110 2111 2112] ]
   *     [ [2113 2114 2115] [2116 2117 2118] [2119 2120 2121] [2122 2123 2124] ]
   *   ]
   ********************************************************************
   * 1-1. result with frames-dim 3 (3:4:2:2)
   *   [
   *     [ [1101 1102 1103] [1104 1105 1106] [1107 1108 1109] [1110 1111 1112] ]
   *     [ [1113 1114 1115] [1116 1117 1118] [1119 1120 1121] [1122 1123 1124] ]
   *   ]
   *   [
   *     [ [2101 2102 2103] [2104 2105 2106] [2107 2108 2109] [2110 2111 2112] ]
   *     [ [2113 2114 2115] [2116 2117 2118] [2119 2120 2121] [2122 2123 2124] ]
   *   ]
   ********************************************************************
   * 1-2. result with frames-dim 2 (3:4:4:1)
   *   [
   *     [ [1101 1102 1103] [1104 1105 1106] [1107 1108 1109] [1110 1111 1112] ]
   *     [ [1113 1114 1115] [1116 1117 1118] [1119 1120 1121] [1122 1123 1124] ]
   *     [ [2101 2102 2103] [2104 2105 2106] [2107 2108 2109] [2110 2111 2112] ]
   *     [ [2113 2114 2115] [2116 2117 2118] [2119 2120 2121] [2122 2123 2124] ]
   *   ]
   ********************************************************************
   * 1-3. result with frames-dim 1 (3:8:2:1)
   *   [
   *     [ [1101 1102 1103] [1104 1105 1106] [1107 1108 1109] [1110 1111 1112]
   *       [2101 2102 2103] [2104 2105 2106] [2107 2108 2109] [2110 2111 2112] ]
   *     [ [1113 1114 1115] [1116 1117 1118] [1119 1120 1121] [1122 1123 1124]
   *       [2113 2114 2115] [2116 2117 2118] [2119 2120 2121] [2122 2123 2124] ]
   *   ]
   ********************************************************************
   * 1-4. result with frames-dim 0 (6:4:2:1)
   *   [
   *     [ [1101 1102 1103 2101 2102 2103] [1104 1105 1106 2104 2105 2106]
   *       [1107 1108 1109 2107 2108 2109] [1110 1111 1112 2110 2111 2112] ]
   *     [ [1113 1114 1115 2113 2114 2115] [1116 1117 1118 2116 2117 2118]
   *       [1119 1120 1121 2119 2120 2121] [1122 1123 1124 2122 2123 2124] ]
   *   ]
   ********************************************************************
   * Ex2) concatenate 2 frames with dimension 3:4:2:2
   ********************************************************************
   * frame 1
   *   [
   *     [ [1101 1102 1103] [1104 1105 1106] [1107 1108 1109] [1110 1111 1112] ]
   *     [ [1113 1114 1115] [1116 1117 1118] [1119 1120 1121] [1122 1123 1124] ]
   *   ]
   *   [
   *     [ [1201 1202 1203] [1204 1205 1206] [1207 1208 1209] [1210 1211 1212] ]
   *     [ [1213 1214 1215] [1216 1217 1218] [1219 1220 1221] [1222 1223 1224] ]
   *   ]
   *
   * frame 2
   *   [
   *     [ [2101 2102 2103] [2104 2105 2106] [2107 2108 2109] [2110 2111 2112] ]
   *     [ [2113 2114 2115] [2116 2117 2118] [2119 2120 2121] [2122 2123 2124] ]
   *   ]
   *   [
   *     [ [2201 2202 2203] [2204 2205 2206] [2207 2208 2209] [2210 2211 2212] ]
   *     [ [2213 2214 2215] [2216 2217 2218] [2219 2220 2221] [2222 2223 2224] ]
   *   ]
   ********************************************************************
   * 2-1. result with frames-dim 3 (3:4:2:4)
   *   [
   *     [ [1101 1102 1103] [1104 1105 1106] [1107 1108 1109] [1110 1111 1112] ]
   *     [ [1113 1114 1115] [1116 1117 1118] [1119 1120 1121] [1122 1123 1124] ]
   *   ]
   *   [
   *     [ [1201 1202 1203] [1204 1205 1206] [1207 1208 1209] [1210 1211 1212] ]
   *     [ [1213 1214 1215] [1216 1217 1218] [1219 1220 1221] [1222 1223 1224] ]
   *   ]
   *   [
   *     [ [2101 2102 2103] [2104 2105 2106] [2107 2108 2109] [2110 2111 2112] ]
   *     [ [2113 2114 2115] [2116 2117 2118] [2119 2120 2121] [2122 2123 2124] ]
   *   ]
   *   [
   *     [ [2201 2202 2203] [2204 2205 2206] [2207 2208 2209] [2210 2211 2212] ]
   *     [ [2213 2214 2215] [2216 2217 2218] [2219 2220 2221] [2222 2223 2224] ]
   *   ]
   ********************************************************************
   * 2-2. result with frames-dim 2 (3:4:4:2)
   *   [
   *     [ [1101 1102 1103] [1104 1105 1106] [1107 1108 1109] [1110 1111 1112] ]
   *     [ [1113 1114 1115] [1116 1117 1118] [1119 1120 1121] [1122 1123 1124] ]
   *     [ [2101 2102 2103] [2104 2105 2106] [2107 2108 2109] [2110 2111 2112] ]
   *     [ [2113 2114 2115] [2116 2117 2118] [2119 2120 2121] [2122 2123 2124] ]
   *   ]
   *   [
   *     [ [1201 1202 1203] [1204 1205 1206] [1207 1208 1209] [1210 1211 1212] ]
   *     [ [1213 1214 1215] [1216 1217 1218] [1219 1220 1221] [1222 1223 1224] ]
   *     [ [2201 2202 2203] [2204 2205 2206] [2207 2208 2209] [2210 2211 2212] ]
   *     [ [2213 2214 2215] [2216 2217 2218] [2219 2220 2221] [2222 2223 2224] ]
   *   ]
   ********************************************************************
   * 2-3. result with frames-dim 1 (3:8:2:2)
   *   [
   *     [ [1101 1102 1103] [1104 1105 1106] [1107 1108 1109] [1110 1111 1112]
   *       [2101 2102 2103] [2104 2105 2106] [2107 2108 2109] [2110 2111 2112] ]
   *     [ [1113 1114 1115] [1116 1117 1118] [1119 1120 1121] [1122 1123 1124]
   *       [2113 2114 2115] [2116 2117 2118] [2119 2120 2121] [2122 2123 2124] ]
   *   ]
   *   [
   *     [ [1201 1202 1203] [1204 1205 1206] [1207 1208 1209] [1210 1211 1212]
   *       [2201 2202 2203] [2204 2205 2206] [2207 2208 2209] [2210 2211 2212] ]
   *     [ [1213 1214 1215] [1216 1217 1218] [1219 1220 1221] [1222 1223 1224]
   *       [2213 2214 2215] [2216 2217 2218] [2219 2220 2221] [2222 2223 2224] ]
   *   ]
   ********************************************************************
   * 2-4. result with frames-dim 0 (6:4:2:2)
   *   [
   *     [ [1101 1102 1103 2101 2102 2103] [1104 1105 1106 2104 2105 2106]
   *       [1107 1108 1109 2107 2108 2109] [1110 1111 1112 2110 2111 2112] ]
   *     [ [1113 1114 1115 2113 2114 2115] [1116 1117 1118 2116 2117 2118]
   *       [1119 1120 1121 2119 2120 2121] [1122 1123 1124 2122 2123 2124] ]
   *   ]
   *   [
   *     [ [1201 1202 1203 2201 2202 2203] [1204 1205 1206 2204 2205 2206]
   *       [1207 1208 1209 2207 2208 2209] [1210 1211 1212 2210 2211 2212] ]
   *     [ [1213 1214 1215 2213 2214 2215] [1216 1217 1218 2216 2217 2218]
   *       [1219 1220 1221 2219 2220 2221] [1222 1223 1224 2222 2223 2224] ]
   *   ]
   ********************************************************************
   * Ex3) concatenate 2 frames with dimension 3:4:1:1
   ********************************************************************
   * frame 1
   *   [
   *     [ [1101 1102 1103] [1104 1105 1106] [1107 1108 1109] [1110 1111 1112] ]
   *   ]
   *
   * frame 2
   *   [
   *     [ [2101 2102 2103] [2104 2105 2106] [2107 2108 2109] [2110 2111 2112] ]
   *   ]
   ********************************************************************
   * 3-1. result with frames-dim 3 (3:4:1:2)
   *   [
   *     [ [1101 1102 1103] [1104 1105 1106] [1107 1108 1109] [1110 1111 1112] ]
   *   ]
   *   [
   *     [ [2101 2102 2103] [2104 2105 2106] [2107 2108 2109] [2110 2111 2112] ]
   *   ]
   ********************************************************************
   * 3-2. result with frames-dim 2 (3:4:2:1)
   *   [
   *     [ [1101 1102 1103] [1104 1105 1106] [1107 1108 1109] [1110 1111 1112] ]
   *     [ [2101 2102 2103] [2104 2105 2106] [2107 2108 2109] [2110 2111 2112] ]
   *   ]
   ********************************************************************
   * 3-3. result with frames-dim 1 (3:8:1:1)
   *   [
   *     [ [1101 1102 1103] [1104 1105 1106] [1107 1108 1109] [1110 1111 1112]
   *       [2101 2102 2103] [2104 2105 2106] [2107 2108 2109] [2110 2111 2112] ]
   *   ]
   ********************************************************************
   * 3-4. result with frames-dim 0 (6:4:1:1)
   *   [
   *     [ [1101 1102 1103 2101 2102 2103] [1104 1105 1106 2104 2105 2106]
   *       [1107 1108 1109 2107 2108 2109] [1110 1111 1112 2110 2111 2112] ]
   *   ]
   ********************************************************************
   */

  /** get block size */
  block_size = gst_tensor_get_element_size (info->type);
  for (f = 0; f <= self->frames_dim; f++) {
    block_size *= info->dimension[f];
  }

  src_idx = dest_idx = 0;

  do {
    for (f = 0; f < self->frames_out; f++) {
      nns_memcpy (dest_info.data + dest_idx,
          src_info.data + src_idx + (frame_size * f), block_size);
      dest_idx += block_size;
    }

    src_idx += block_size;

    g_assert (src_idx <= frame_size);
    g_assert (dest_idx <= dest_info.size);
  } while (src_idx < frame_size);

  gst_buffer_unmap (srcbuf, &src_info);
  gst_buffer_unmap (outbuf, &dest_info);

  gst_buffer_unref (srcbuf);
}
Ejemplo n.º 29
0
static GstFlowReturn
gst_v4l2_buffer_pool_acquire_buffer (GstBufferPool * bpool, GstBuffer ** buffer,
    GstBufferPoolAcquireParams * params)
{
  GstFlowReturn ret;
  GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool);
  GstV4l2Object *obj = pool->obj;

  GST_DEBUG_OBJECT (pool, "acquire");

  if (GST_BUFFER_POOL_IS_FLUSHING (bpool))
    goto flushing;

  switch (obj->type) {
    case V4L2_BUF_TYPE_VIDEO_CAPTURE:
      /* capture, This function should return a buffer with new captured data */
      switch (obj->mode) {
        case GST_V4L2_IO_RW:
          /* take empty buffer from the pool */
          ret = GST_BUFFER_POOL_CLASS (parent_class)->acquire_buffer (bpool,
              buffer, params);
          break;

        case GST_V4L2_IO_MMAP:
          /* just dequeue a buffer, we basically use the queue of v4l2 as the
           * storage for our buffers. This function does poll first so we can
           * interrupt it fine. */
          ret = gst_v4l2_buffer_pool_dqbuf (pool, buffer);
          if (G_UNLIKELY (ret != GST_FLOW_OK))
            goto done;

          /* start copying buffers when we are running low on buffers */
          if (pool->num_queued < pool->copy_threshold) {
            GstBuffer *copy;

            /* copy the memory */
            copy = gst_buffer_copy (*buffer);
            GST_LOG_OBJECT (pool, "copy buffer %p->%p", *buffer, copy);

            /* and requeue so that we can continue capturing */
            ret = gst_v4l2_buffer_pool_qbuf (pool, *buffer);
            *buffer = copy;
          }
          break;

        case GST_V4L2_IO_USERPTR:
        default:
          g_assert_not_reached ();
          break;
      }
      break;

    case V4L2_BUF_TYPE_VIDEO_OUTPUT:
      /* playback, This function should return an empty buffer */
      switch (obj->mode) {
        case GST_V4L2_IO_RW:
          /* get an empty buffer */
          ret = GST_BUFFER_POOL_CLASS (parent_class)->acquire_buffer (bpool,
              buffer, params);
          break;

        case GST_V4L2_IO_MMAP:
          /* get a free unqueued buffer */
          ret = GST_BUFFER_POOL_CLASS (parent_class)->acquire_buffer (bpool,
              buffer, params);
          break;

        case GST_V4L2_IO_USERPTR:
        default:
          g_assert_not_reached ();
          break;
      }
      break;

    default:
      g_assert_not_reached ();
      break;
  }
done:
  return ret;

  /* ERRORS */
flushing:
  {
    GST_DEBUG_OBJECT (pool, "We are flushing");
    return GST_FLOW_FLUSHING;
  }
}
Ejemplo n.º 30
0
static GstFlowReturn
dvdspu_handle_vid_buffer (GstDVDSpu * dvdspu, GstBuffer * buf)
{
  GstClockTime new_ts;
  GstFlowReturn ret;
  gboolean using_ref = FALSE;

  DVD_SPU_LOCK (dvdspu);

  if (buf == NULL) {
    GstClockTime next_ts = dvdspu->video_seg.position;

    next_ts += gst_util_uint64_scale_int (GST_SECOND,
        dvdspu->spu_state.info.fps_d, dvdspu->spu_state.info.fps_n);

    /* NULL buffer was passed - use the reference frame and update the timestamp,
     * or else there's nothing to draw, and just return GST_FLOW_OK */
    if (dvdspu->ref_frame == NULL) {
      dvdspu->video_seg.position = next_ts;
      goto no_ref_frame;
    }

    buf = gst_buffer_copy (dvdspu->ref_frame);

#if 0
    g_print ("Duping frame %" GST_TIME_FORMAT " with new TS %" GST_TIME_FORMAT
        "\n", GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
        GST_TIME_ARGS (next_ts));
#endif

    GST_BUFFER_TIMESTAMP (buf) = next_ts;
    using_ref = TRUE;
  }

  if (GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
    dvdspu->video_seg.position = GST_BUFFER_TIMESTAMP (buf);
  }

  new_ts = gst_segment_to_running_time (&dvdspu->video_seg, GST_FORMAT_TIME,
      dvdspu->video_seg.position);

#if 0
  g_print ("TS %" GST_TIME_FORMAT " running: %" GST_TIME_FORMAT "\n",
      GST_TIME_ARGS (dvdspu->video_seg.position), GST_TIME_ARGS (new_ts));
#endif

  gst_dvd_spu_advance_spu (dvdspu, new_ts);

  /* If we have an active SPU command set, we store a copy of the frame in case
   * we hit a still and need to draw on it. Otherwise, a reference is
   * sufficient in case we later encounter a still */
  if ((dvdspu->spu_state.flags & SPU_STATE_FORCED_DSP) ||
      ((dvdspu->spu_state.flags & SPU_STATE_FORCED_ONLY) == 0 &&
          (dvdspu->spu_state.flags & SPU_STATE_DISPLAY))) {
    if (using_ref == FALSE) {
      GstBuffer *copy;

      /* Take a copy in case we hit a still frame and need the pristine 
       * frame around */
      copy = gst_buffer_copy (buf);
      gst_buffer_replace (&dvdspu->ref_frame, copy);
      gst_buffer_unref (copy);
    }

    /* Render the SPU overlay onto the buffer */
    buf = gst_buffer_make_writable (buf);

    gstspu_render (dvdspu, buf);
  } else {
    if (using_ref == FALSE) {
      /* Not going to draw anything on this frame, just store a reference
       * in case we hit a still frame and need it */
      gst_buffer_replace (&dvdspu->ref_frame, buf);
    }
  }

  if (dvdspu->spu_state.flags & SPU_STATE_STILL_FRAME) {
    GST_DEBUG_OBJECT (dvdspu, "Outputting buffer with TS %" GST_TIME_FORMAT
        "from chain while in still",
        GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)));
  }

  DVD_SPU_UNLOCK (dvdspu);

  /* just push out the incoming buffer without touching it */
  ret = gst_pad_push (dvdspu->srcpad, buf);

  return ret;

no_ref_frame:

  DVD_SPU_UNLOCK (dvdspu);

  return GST_FLOW_OK;
}