~ubuntu-branches/ubuntu/vivid/media-hub/vivid-updates

« back to all changes in this revision

Viewing changes to src/core/media/gstreamer/playbin.h

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-11-04 06:10:54 UTC
  • mfrom: (1.1.22)
  • Revision ID: package-import@ubuntu.com-20141104061054-m5de4s9l0qcpd5cb
Tags: 2.0.0+15.04.20141104-0ubuntu1
New rebuild forced

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include <chrono>
32
32
#include <string>
33
33
 
 
34
// Uncomment to generate a dot file at the time that the pipeline
 
35
// goes to the PLAYING state. Make sure to export GST_DEBUG_DUMP_DOT_DIR
 
36
// before starting media-hub-server. To convert the dot file to something
 
37
// other image format, use: dot pipeline.dot -Tpng -o pipeline.png
 
38
//#define DEBUG_GST_PIPELINE
 
39
 
34
40
namespace media = core::ubuntu::media;
35
41
 
36
42
namespace gstreamer
68
74
        : pipeline(gst_element_factory_make("playbin", pipeline_name().c_str())),
69
75
          bus{gst_element_get_bus(pipeline)},
70
76
          file_type(MEDIA_FILE_TYPE_NONE),
 
77
          video_sink(nullptr),
 
78
          video_height(0),
 
79
          video_width(0),
71
80
          on_new_message_connection(
72
81
              bus.on_new_message.connect(
73
82
                  std::bind(
153
162
            signals.on_info(message.detail.error_warning_info);
154
163
            break;
155
164
        case GST_MESSAGE_TAG:
156
 
            signals.on_tag_available(message.detail.tag);
 
165
            {
 
166
                gchar *orientation;
 
167
                if (gst_tag_list_get_string(message.detail.tag.tag_list, "image-orientation", &orientation))
 
168
                {
 
169
                    // If the image-orientation tag is in the GstTagList, signal the Engine
 
170
                    signals.on_orientation_changed(orientation_lut(orientation));
 
171
                    g_free (orientation);
 
172
                }
 
173
 
 
174
                signals.on_tag_available(message.detail.tag);
 
175
            }
157
176
            break;
158
177
        case GST_MESSAGE_STATE_CHANGED:
159
178
            signals.on_state_changed(message.detail.state_changed);
204
223
 
205
224
        if (::getenv("CORE_UBUNTU_MEDIA_SERVICE_VIDEO_SINK_NAME") != nullptr)
206
225
        {
207
 
            auto video_sink = gst_element_factory_make (
208
 
                    ::getenv("CORE_UBUNTU_MEDIA_SERVICE_VIDEO_SINK_NAME"),
209
 
                    "video-sink");
 
226
            video_sink = gst_element_factory_make (
 
227
                ::getenv("CORE_UBUNTU_MEDIA_SERVICE_VIDEO_SINK_NAME"),
 
228
                "video-sink");
210
229
 
211
230
            std::cout << "video_sink: " << ::getenv("CORE_UBUNTU_MEDIA_SERVICE_VIDEO_SINK_NAME") << std::endl;
212
231
 
224
243
 
225
244
        if (::getenv("CORE_UBUNTU_MEDIA_SERVICE_VIDEO_SINK_NAME") != nullptr)
226
245
        {
227
 
            GstElement *video_sink = NULL;
228
246
            g_object_get (pipeline, "video_sink", &video_sink, NULL);
229
247
 
230
248
            // Get the service-side BufferQueue (IGraphicBufferProducer) and associate it with
265
283
        }
266
284
    }
267
285
 
 
286
    media::Player::Orientation orientation_lut(const gchar *orientation)
 
287
    {
 
288
        if (g_strcmp0(orientation, "rotate-0") == 0)
 
289
            return media::Player::Orientation::rotate0;
 
290
        else if (g_strcmp0(orientation, "rotate-90") == 0)
 
291
            return media::Player::Orientation::rotate90;
 
292
        else if (g_strcmp0(orientation, "rotate-180") == 0)
 
293
            return media::Player::Orientation::rotate180;
 
294
        else if (g_strcmp0(orientation, "rotate-270") == 0)
 
295
            return media::Player::Orientation::rotate270;
 
296
        else
 
297
            return media::Player::Orientation::rotate0;
 
298
    }
 
299
 
268
300
    /** Sets the new audio stream role on the pulsesink in playbin */
269
301
    void set_audio_stream_role(media::Player::AudioStreamRole new_audio_role)
270
302
    {
350
382
                        &current,
351
383
                        &pending,
352
384
                        state_change_timeout.count());
 
385
 
 
386
        if (new_state == GST_STATE_PLAYING)
 
387
        {
 
388
            // Get the video height/width from the video sink
 
389
            get_video_dimensions();
 
390
#ifdef DEBUG_GST_PIPELINE
 
391
            std::cout << "Dumping pipeline dot file" << std::endl;
 
392
            GST_DEBUG_BIN_TO_DOT_FILE((GstBin*)pipeline, GST_DEBUG_GRAPH_SHOW_ALL, "pipeline");
 
393
#endif
 
394
        }
353
395
            break;
354
396
        }
355
397
 
366
408
                    ms.count() * 1000);
367
409
    }
368
410
 
 
411
    void get_video_dimensions()
 
412
    {
 
413
        if (video_sink != nullptr && g_strcmp0(::getenv("CORE_UBUNTU_MEDIA_SERVICE_VIDEO_SINK_NAME"), "mirsink") == 0)
 
414
        {
 
415
            g_object_get (video_sink, "height", &video_height, nullptr);
 
416
            g_object_get (video_sink, "width", &video_width, nullptr);
 
417
            std::cout << "video_height: " << video_height << ", video_width: " << video_width << std::endl;
 
418
            signals.on_add_frame_dimension(video_height, video_width);
 
419
        }
 
420
        else
 
421
            std::cerr << "Could not get the height/width of each video frame" << std::endl;
 
422
    }
 
423
 
 
424
    int get_video_height() const
 
425
    {
 
426
        return video_height;
 
427
    }
 
428
 
 
429
    int get_video_width() const
 
430
    {
 
431
        return video_width;
 
432
    }
 
433
 
369
434
    std::string get_file_content_type(const std::string& uri) const
370
435
    {
371
436
        if (uri.empty())
445
510
    gstreamer::Bus bus;
446
511
    MediaFileType file_type;
447
512
    SurfaceTextureClientHybris stc_hybris;
 
513
    GstElement* video_sink;
 
514
    uint32_t video_height;
 
515
    uint32_t video_width;
448
516
    core::Connection on_new_message_connection;
449
517
    bool is_seeking;
450
518
    struct
458
526
        core::Signal<uint64_t> on_seeked_to;
459
527
        core::Signal<void> on_end_of_stream;
460
528
        core::Signal<media::Player::PlaybackStatus> on_playback_status_changed;
 
529
        core::Signal<media::Player::Orientation> on_orientation_changed;
 
530
        core::Signal<uint32_t, uint32_t> on_add_frame_dimension;
461
531
        core::Signal<void> client_disconnected;
462
532
    } signals;
463
533
};