title: How to use GstReferenceTimestampMeta properly
body: <p>My goal is to attach timestamps to <code>GstBuffer</code> which is independent of GST time. I found <a href="https://gstreamer.freedesktop.org/documentation/gstreamer/gstbuffer.html?gi-language=c#GstReferenceTimestampMeta" rel="nofollow noreferrer">GstReferenceTimestampMeta</a>, which looks exactly what I am after. However I have some issues when trying to utilize it. Maybe I have misundestood the usage of the GstMeta structure.</p>
  <p>Brief overview of pipeline:</p>
  <p>server: <code>appsrc -&gt; h265enc -&gt; rtp -&gt; udpsink</code></p>
  <p>client: <code>udpsrc -&gt; h265decode -&gt; appsink</code></p>
  <p>What I am doing in the server is to attach the <code>GstMeta</code> to a <code>GstBuffer</code> before pushing the buffer into the <code>appsrc</code>, as such:</p>
  <pre class="lang-cpp prettyprint-override"><code>auto buffer = gst_buffer_new_allocate(NULL, buffer_size, NULL);
  
  // ------------------------- GstReferenceTimestampMeta START
  
  GstCaps *caps = gst_caps_from_string(&quot;timestamp/x-test-stream&quot;);
  gst_buffer_add_reference_timestamp_meta(
    buffer,
    caps,
    timestamp.nanoseconds(),
    GST_CLOCK_TIME_NONE 
  );  
  
  // ------------------------- GstReferenceTimestampMeta END
      
  GstMapInfo info;
  gst_buffer_map(buffer, &amp;info, GST_MAP_READ);
  std::memcpy(info.data, image.data, buffer_size);
  gst_buffer_unmap(buffer, &amp;info);
  gst_app_src_push_buffer(GST_APP_SRC(appsrc_), buffer);
  </code></pre>
  <p>Similarly, what I do at the client side is:</p>
  <pre class="lang-cpp prettyprint-override"><code>GstSample *sample = gst_app_sink_try_pull_sample(GST_APP_SINK(appsink_), 10000000);
  GstBuffer *buffer = gst_sample_get_buffer(sample);
  
  // ------------------------- GstReferenceTimestampMeta START
  
  GstReferenceTimestampMeta *meta;
  GstCaps *reference = gst_caps_from_string(&quot;timestamp/x-test-stream&quot;);
  meta = gst_buffer_get_reference_timestamp_meta(buffer, reference);
  if (meta == NULL){
    std::cout &lt;&lt; &quot;daim&quot; &lt;&lt; std::endl;   
    break;
  }
  else {
    std::cout &lt;&lt; meta-&gt;timestamp &lt;&lt; std::endl; 
  }
  
  // ------------------------- GstReferenceTimestampMeta END
  
  MapInfo buffer_mapping;
  gst_buffer_map(buffer, &amp;buffer_mapping, GST_MAP_READ);
  GstCaps *caps = gst_sample_get_caps(sample);
  
  GstStructure *properties = gst_caps_get_structure(caps, 0);
  
  int width, height;
  gst_structure_get_int(properties, &quot;width&quot;, &amp;width);
  gst_structure_get_int(properties, &quot;height&quot;, &amp;height);
  std::string format = gst_structure_get_string(properties, &quot;format&quot;);
  
  int numChannels = (format == &quot;BGR&quot;) ? 3 : 1;
  
  renderTracks(buffer_mapping.data, width, height, numChannels);
  
  loadBufferOnDevice(width, height, numChannels, buffer_mapping.data);
  
  gst_buffer_unmap(buffer, &amp;buffer_mapping);
  gst_sample_unref(sample);
  
  </code></pre>
  <p>The result here is &quot;daim&quot; printed to cout as the <code>GstMeta</code> with reference caps &quot;timestamp/x-test-stream&quot; is not found, and thus the variable <code>meta == NULL</code>.</p>
  <p>I might have misundestood the usage of the GstMeta structure. Hopefully someone can point me in the right direction. If there are other methods of attaching &quot;custom&quot; timestamp to a buffer, please let me know!</p>