Advertisement
Guest User

select_tracks_for_object

a guest
Dec 3rd, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. static GPtrArray*
  2. select_tracks_for_object(GESTimeline* timeline, GESClip* clip, GESTrackElement* tr_object, gpointer user_data)
  3. {
  4. GPtrArray* result = NULL;
  5.  
  6. std::lock_guard<std::mutex> lck(timelines_mtx);
  7.  
  8. auto it = timelines.find(timeline);
  9. if (it != timelines.end())
  10. {
  11. auto timeline_data = it->second;
  12. auto skip = false;
  13.  
  14. // if the clip was found, use stream selection logic to possibly skip this GESTrackElement
  15. auto it2 = timeline_data->clips.find(clip);
  16. if (it2 != timeline_data->clips.end())
  17. {
  18. auto clip_data = it2->second;
  19.  
  20. const gchar* name = ges_uri_clip_get_uri(GES_URI_CLIP(clip));
  21. gchar target_stream_id[256] = { 0 };
  22.  
  23.  
  24. if (GES_IS_URI_CLIP_ASSET(GES_TIMELINE_ELEMENT(clip)->asset))
  25. {
  26. auto clip_asset = GES_URI_CLIP_ASSET(GES_TIMELINE_ELEMENT(clip)->asset);
  27. auto info = ges_uri_clip_asset_get_info(clip_asset);
  28.  
  29. auto streams = gst_discoverer_info_get_audio_streams(info);
  30.  
  31. int stream_idx = 0;
  32. for (GList* tmp = streams; tmp; tmp = tmp->next)
  33. {
  34. if (GST_IS_DISCOVERER_AUDIO_INFO(tmp->data))
  35. {
  36. const gchar* stream_id = gst_discoverer_stream_info_get_stream_id(GST_DISCOVERER_STREAM_INFO(tmp->data));
  37.  
  38. if (stream_idx == clip_data->target_stream)
  39. {
  40. strcpy(target_stream_id, stream_id);
  41. g_print("Correct stream id: %s\n", stream_id);
  42. break;
  43. }
  44. stream_idx++;
  45. }
  46. }
  47. }
  48.  
  49. GESAsset* asset = ges_extractable_get_asset(GES_EXTRACTABLE(tr_object));
  50.  
  51. if (GES_IS_URI_SOURCE_ASSET(asset))
  52. {
  53. GstDiscovererStreamInfo* stream_info = ges_uri_source_asset_get_stream_info(GES_URI_SOURCE_ASSET(asset));
  54.  
  55. const gchar* stream_id = gst_discoverer_stream_info_get_stream_id(stream_info);
  56. g_print("StreamID: %s, Clip: %s, Stream Caps: %s, target_stream = %d\n", stream_id, name, gst_caps_to_string(gst_discoverer_stream_info_get_caps(stream_info)), clip_data->target_stream);
  57.  
  58. if (strcmp(target_stream_id, stream_id) != 0)
  59. {
  60. skip = true;
  61. g_print("skipping...\n");
  62. }
  63. }
  64. }
  65. else
  66. {
  67. g_print("[CLIP WAS NOT FOUND]\n");
  68. }
  69.  
  70. if (!skip)
  71. {
  72. result = g_ptr_array_new();
  73.  
  74. for (GList* tmp = timeline->tracks; tmp; tmp = tmp->next)
  75. {
  76. GESTrack* track = GES_TRACK(tmp->data);
  77.  
  78. if ((track->type & ges_track_element_get_track_type(tr_object)))
  79. {
  80. GESAsset* asset = ges_extractable_get_asset(GES_EXTRACTABLE(tr_object));
  81.  
  82. if (GES_IS_URI_SOURCE_ASSET(asset))
  83. {
  84. GstDiscovererStreamInfo* stream_info = ges_uri_source_asset_get_stream_info(GES_URI_SOURCE_ASSET(asset));
  85.  
  86. const gchar* stream_id = gst_discoverer_stream_info_get_stream_id(stream_info);
  87. g_print("[SELECTED STREAM ID]: %s\n", stream_id);
  88. }
  89. else
  90. {
  91. const gchar* name = G_OBJECT_TYPE_NAME(tr_object);
  92. g_print("[WHAT IS THIS?!?]: %s\n", name);
  93. }
  94.  
  95. gst_object_ref(track);
  96. g_ptr_array_add(result, track);
  97. break;
  98. }
  99. }
  100. }
  101. }
  102.  
  103. return result;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement