Merge lp:~justinmcp/media-hub/oxide-support into lp:~phablet-team/media-hub/oxide-support

Proposed by Justin McPherson
Status: Merged
Approved by: Jim Hodapp
Approved revision: 45
Merged at revision: 43
Proposed branch: lp:~justinmcp/media-hub/oxide-support
Merge into: lp:~phablet-team/media-hub/oxide-support
Diff against target: 209 lines (+87/-8)
8 files modified
src/core/media/engine.h (+3/-0)
src/core/media/gstreamer/bus.h (+3/-1)
src/core/media/gstreamer/engine.cpp (+7/-0)
src/core/media/gstreamer/engine.h (+3/-0)
src/core/media/gstreamer/playbin.h (+44/-1)
src/core/media/player_implementation.cpp (+1/-5)
src/core/media/player_stub.cpp (+1/-1)
tests/unit-tests/test-gstreamer-engine.cpp (+25/-0)
To merge this branch: bzr merge lp:~justinmcp/media-hub/oxide-support
Reviewer Review Type Date Requested Status
Jim Hodapp (community) code Approve
Review via email: mp+233152@code.launchpad.net

Commit message

Support user-agent and cookies headers in http(s) source.

To post a comment you must log in.
Revision history for this message
Jim Hodapp (jhodapp) wrote :

Just one fix needed.

review: Needs Fixing (code)
45. By Justin McPherson <justin@phablet-dev>

Check for a null source in callback.

Revision history for this message
Jim Hodapp (jhodapp) wrote :

Looks good, thanks.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/core/media/engine.h'
2--- src/core/media/engine.h 2014-04-25 17:53:00 +0000
3+++ src/core/media/engine.h 2014-09-15 01:19:37 +0000
4@@ -98,6 +98,9 @@
5 virtual const core::Property<State>& state() const = 0;
6
7 virtual bool open_resource_for_uri(const Track::UriType& uri) = 0;
8+ virtual bool open_resource_for_uri(const core::ubuntu::media::Track::UriType& uri,
9+ const std::string& cookies,
10+ const std::string& user_agent) = 0;
11 virtual void create_video_sink(uint32_t texture_id) = 0;
12
13 virtual bool play() = 0;
14
15=== modified file 'src/core/media/gstreamer/bus.h'
16--- src/core/media/gstreamer/bus.h 2014-02-12 15:53:57 +0000
17+++ src/core/media/gstreamer/bus.h 2014-09-15 01:19:37 +0000
18@@ -208,7 +208,9 @@
19 break;
20 case GST_MESSAGE_ANY:
21 break;
22- }
23+ default:
24+ break;
25+ }
26 }
27
28 GstMessage* message;
29
30=== modified file 'src/core/media/gstreamer/engine.cpp'
31--- src/core/media/gstreamer/engine.cpp 2014-04-25 17:53:00 +0000
32+++ src/core/media/gstreamer/engine.cpp 2014-09-15 01:19:37 +0000
33@@ -271,6 +271,13 @@
34 return true;
35 }
36
37+bool gstreamer::Engine::open_resource_for_uri(const media::Track::UriType& uri, const std::string& cookies,
38+ const std::string& user_agent)
39+{
40+ d->playbin.set_uri(uri, cookies, user_agent);
41+ return true;
42+}
43+
44 void gstreamer::Engine::create_video_sink(uint32_t texture_id)
45 {
46 d->playbin.create_video_sink(texture_id);
47
48=== modified file 'src/core/media/gstreamer/engine.h'
49--- src/core/media/gstreamer/engine.h 2014-04-25 17:53:00 +0000
50+++ src/core/media/gstreamer/engine.h 2014-09-15 01:19:37 +0000
51@@ -33,6 +33,9 @@
52 const core::Property<State>& state() const;
53
54 bool open_resource_for_uri(const core::ubuntu::media::Track::UriType& uri);
55+ bool open_resource_for_uri(const core::ubuntu::media::Track::UriType& uri,
56+ const std::string& cookies,
57+ const std::string& user_agent);
58 void create_video_sink(uint32_t texture_id);
59
60 bool play();
61
62=== modified file 'src/core/media/gstreamer/playbin.h'
63--- src/core/media/gstreamer/playbin.h 2014-04-25 21:23:10 +0000
64+++ src/core/media/gstreamer/playbin.h 2014-09-15 01:19:37 +0000
65@@ -64,6 +64,13 @@
66 thiz->signals.about_to_finish();
67 }
68
69+ static void source_setup(GstElement*,
70+ GstElement *source,
71+ gpointer user_data)
72+ {
73+ static_cast<Playbin*>(user_data)->setup_source(source);
74+ }
75+
76 Playbin()
77 : pipeline(gst_element_factory_make("playbin", pipeline_name().c_str())),
78 bus{gst_element_get_bus(pipeline)},
79@@ -90,6 +97,13 @@
80 this
81 );
82
83+ g_signal_connect(
84+ pipeline,
85+ "source-setup",
86+ G_CALLBACK(source_setup),
87+ this
88+ );
89+
90 // When a client of media-hub dies, call on_client_died
91 decoding_service_set_client_death_cb(&Playbin::on_client_died_cb, static_cast<void*>(this));
92 }
93@@ -258,13 +272,40 @@
94 return static_cast<uint64_t>(dur);
95 }
96
97- void set_uri(const std::string& uri)
98+ void set_uri(const std::string& uri,
99+ const std::string& cookies = std::string(),
100+ const std::string& user_agent = std::string())
101 {
102 g_object_set(pipeline, "uri", uri.c_str(), NULL);
103 if (is_video_file(uri))
104 file_type = MEDIA_FILE_TYPE_VIDEO;
105 else if (is_audio_file(uri))
106 file_type = MEDIA_FILE_TYPE_AUDIO;
107+
108+ request_cookies = cookies;
109+ request_user_agent = user_agent;
110+ }
111+
112+ void setup_source(GstElement *source)
113+ {
114+ if (source == NULL)
115+ return;
116+
117+ if (!request_cookies.empty()) {
118+ if (g_object_class_find_property(G_OBJECT_GET_CLASS(source),
119+ "cookies") != NULL) {
120+ gchar ** cookies = g_strsplit(request_cookies.c_str(), ";", 0);
121+ g_object_set(source, "cookies", cookies, NULL);
122+ g_strfreev(cookies);
123+ }
124+ }
125+
126+ if (!request_user_agent.empty()) {
127+ if (g_object_class_find_property(G_OBJECT_GET_CLASS(source),
128+ "user-agent") != NULL) {
129+ g_object_set(source, "user-agent", request_user_agent.c_str(), NULL);
130+ }
131+ }
132 }
133
134 std::string uri() const
135@@ -400,6 +441,8 @@
136 SurfaceTextureClientHybris stc_hybris;
137 core::Connection on_new_message_connection;
138 bool is_seeking;
139+ std::string request_cookies;
140+ std::string request_user_agent;
141 struct
142 {
143 core::Signal<void> about_to_finish;
144
145=== modified file 'src/core/media/player_implementation.cpp'
146--- src/core/media/player_implementation.cpp 2014-07-22 15:03:36 +0000
147+++ src/core/media/player_implementation.cpp 2014-09-15 01:19:37 +0000
148@@ -279,11 +279,7 @@
149 bool media::PlayerImplementation::open_uri(const Track::UriType& uri, const std::string& cookies,
150 const std::string& user_agent)
151 {
152- // TODO: Implement this for proper Oxide media playback support
153- (void)uri;
154- (void)cookies;
155- (void)user_agent;
156- return true;
157+ return d->engine->open_resource_for_uri(uri, cookies, user_agent);
158 }
159
160 void media::PlayerImplementation::create_video_sink(uint32_t texture_id)
161
162=== modified file 'src/core/media/player_stub.cpp'
163--- src/core/media/player_stub.cpp 2014-07-22 15:03:36 +0000
164+++ src/core/media/player_stub.cpp 2014-09-15 01:19:37 +0000
165@@ -275,7 +275,7 @@
166 return op.value();
167 }
168
169-bool media::PlayerStub::open_uri(const Track::UriType& uri, std::string& cookies,
170+bool media::PlayerStub::open_uri(const Track::UriType& uri, const std::string& cookies,
171 const std::string& user_agent)
172 {
173 auto op = d->object->invoke_method_synchronously<mpris::Player::OpenUriExtended, bool>(uri, cookies, user_agent);
174
175=== modified file 'tests/unit-tests/test-gstreamer-engine.cpp'
176--- tests/unit-tests/test-gstreamer-engine.cpp 2014-06-24 20:37:44 +0000
177+++ tests/unit-tests/test-gstreamer-engine.cpp 2014-09-15 01:19:37 +0000
178@@ -151,6 +151,31 @@
179 std::chrono::seconds{10}));
180 }
181
182+TEST(GStreamerEngine, setting_uri_and_audio_playback_with_http_headers_works)
183+{
184+ const std::string test_audio_uri{"http://stream-dc1.radioparadise.com/mp3-32"};
185+
186+ core::testing::WaitableStateTransition<core::ubuntu::media::Engine::State> wst(
187+ core::ubuntu::media::Engine::State::ready);
188+
189+ gstreamer::Engine engine;
190+
191+ engine.state().changed().connect(
192+ std::bind(
193+ &core::testing::WaitableStateTransition<core::ubuntu::media::Engine::State>::trigger,
194+ std::ref(wst),
195+ std::placeholders::_1));
196+
197+ EXPECT_TRUE(engine.open_resource_for_uri(test_audio_uri, "", "MediaHub"));
198+ EXPECT_TRUE(engine.play());
199+ EXPECT_TRUE(wst.wait_for_state_for(
200+ core::ubuntu::media::Engine::State::playing,
201+ std::chrono::seconds{10}));
202+ EXPECT_TRUE(wst.wait_for_state_for(
203+ core::ubuntu::media::Engine::State::ready,
204+ std::chrono::seconds{10}));
205+}
206+
207 TEST(GStreamerEngine, stop_pause_play_seek_audio_only_works)
208 {
209 const std::string test_file{"/tmp/test.ogg"};

Subscribers

People subscribed via source and target branches