~phablet-team/aethercast/fix-for-microsoft-dongle

« back to all changes in this revision

Viewing changes to src/mcs/testsourcemediamanager.cpp

Add hardware encoding and video streaming support.

The hardware encoding is currently only for Android 5.x based devices. On all others encoding will simply not work. The streaming part of aethercast (MPEGTS packetizing, RTP sending) as based on some code from Android.

Approved by PS Jenkins bot, Thomas Voß, Jim Hodapp.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 *
16
16
 */
17
17
 
 
18
#include <sstream>
 
19
 
18
20
#include <gst/gst.h>
19
21
 
20
22
#include "logger.h"
22
24
#include "utils.h"
23
25
#include "logging.h"
24
26
 
 
27
#include "mcs/video/videoformat.h"
 
28
 
25
29
namespace mcs {
26
30
std::shared_ptr<TestSourceMediaManager> TestSourceMediaManager::create(const std::string &remote_address) {
27
31
    return std::shared_ptr<TestSourceMediaManager>{new TestSourceMediaManager{remote_address}};
35
39
}
36
40
 
37
41
SharedGObject<GstElement> TestSourceMediaManager::ConstructPipeline(const wds::H264VideoFormat &format) {
38
 
    auto config = Utils::Sprintf("videotestsrc ! videoconvert ! video/x-raw,format=I420 ! x264enc ! mpegtsmux ! rtpmp2tpay ! udpsink name=sink host=%s port=%d",
39
 
                                     remote_address_.c_str(), sink_port1_);
 
42
    auto profile = mcs::video::ExtractH264Profile(format);
 
43
    auto rr = mcs::video::ExtractRateAndResolution(format);
 
44
 
 
45
#if 0
 
46
    std::stringstream ss;
 
47
    ss << Utils::Sprintf("videotestsrc ! video/x-raw,format=I420,framerate=%d/1,width=%d,height=%d,pixel-aspect-ratio=1/1 ! ", rr.framerate, rr.width, rr.height);
 
48
    ss << "x264enc tune=zerolatency byte-stream=true ! ";
 
49
    ss << Utils::Sprintf("video/x-h264,profile=%s ! ", profile.c_str());
 
50
    ss << "mpegtsmux ! rtpmp2tpay ! ";
 
51
    ss << Utils::Sprintf("udpsink name=sink host=%s port=%d", remote_address_.c_str(), sink_port1_);
 
52
#else
 
53
    std::stringstream ss;
 
54
    ss << "ximagesrc ! ";
 
55
    ss << Utils::Sprintf("videoconvert ! video/x-raw,format=I420,framerate=%d/1,pixel-aspect-ratio=1/1 ! ", rr.framerate);
 
56
    ss << Utils::Sprintf("videoscale ! video/x-raw,width=%d,height=%d ! ", rr.width, rr.height);
 
57
    ss << "queue2 ! ";
 
58
    ss << "x264enc byte-stream=true tune=zerolatency interlaced=false ! ";
 
59
    ss << Utils::Sprintf("video/x-h264,profile=%s !", profile.c_str());
 
60
    ss << "mpegtsmux ! rtpmp2tpay ! ";
 
61
    ss << Utils::Sprintf("udpsink name=sink host=%s port=%d", remote_address_.c_str(), sink_port1_);
 
62
#endif
 
63
 
 
64
    DEBUG("pipeline: %s", ss.str());
40
65
 
41
66
    GError *error = nullptr;
42
 
    GstElement *pipeline = gst_parse_launch(config.c_str(), &error);
 
67
    GstElement *pipeline = gst_parse_launch(ss.str().c_str(), &error);
43
68
    if (error) {
44
 
        WARNING("Failed to setup GStreamer pipeline: %s", error->message);
 
69
        ERROR("Failed to setup GStreamer pipeline: %s", error->message);
45
70
        g_error_free(error);
46
71
        return nullptr;
47
72
    }