Merge lp:~alfonsosanchezbeato/media-hub/fix-refs into lp:media-hub/stable

Proposed by Alfonso Sanchez-Beato
Status: Merged
Approved by: Simon Fels
Approved revision: 157
Merged at revision: 157
Proposed branch: lp:~alfonsosanchezbeato/media-hub/fix-refs
Merge into: lp:media-hub/stable
Diff against target: 86 lines (+27/-15)
1 file modified
src/core/media/gstreamer/playbin.cpp (+27/-15)
To merge this branch: bzr merge lp:~alfonsosanchezbeato/media-hub/fix-refs
Reviewer Review Type Date Requested Status
Jim Hodapp (community) code Approve
Simon Fels Approve
Review via email: mp+273229@code.launchpad.net

Commit message

Avoid getting additional references for audio_sink, which were not being freed. Also, remove unneeded unrefs that must be performed in gstreamer instead.

Description of the change

Avoid getting additional references for audio_sink, which were not being freed. Also, remove unneeded unrefs that must be performed in gstreamer instead.

To post a comment you must log in.
157. By Alfonso Sanchez-Beato

Avoid getting additional references for audio_sink, which were not being freed.
Also, remove unneeded unrefs that must be performed in gstreamer instead.

Revision history for this message
Simon Fels (morphis) :
review: Approve
Revision history for this message
Simon Fels (morphis) wrote :

Tested with silo 28 on arale. No leaking file descriptors anymore.

Used test script:

 $ while true ; do ls -1 /proc/`pidof media-hub-server`/fd | wc -l ; sleep 1 ; done

While playing different media files with video player and music-app.

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

Looks good and works well.

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/gstreamer/playbin.cpp'
2--- src/core/media/gstreamer/playbin.cpp 2015-09-23 11:17:26 +0000
3+++ src/core/media/gstreamer/playbin.cpp 2015-10-02 14:13:40 +0000
4@@ -136,19 +136,39 @@
5 );
6 }
7
8+// Note that we might be accessing freed memory here, so activate DEBUG_REFS
9+// only for debugging
10+//#define DEBUG_REFS
11+#ifdef DEBUG_REFS
12+static void print_refs(const gstreamer::Playbin &pb, const char *func)
13+{
14+ using namespace std;
15+
16+ cout << func << endl;
17+ if (pb.pipeline)
18+ cout << "pipeline: " << GST_OBJECT_REFCOUNT(pb.pipeline) << endl;
19+ if (pb.video_sink)
20+ cout << "video_sink: " << GST_OBJECT_REFCOUNT(pb.video_sink) << endl;
21+ if (pb.audio_sink)
22+ cout << "audio_sink: " << GST_OBJECT_REFCOUNT(pb.audio_sink) << endl;
23+}
24+#endif
25+
26 gstreamer::Playbin::~Playbin()
27 {
28+#ifdef DEBUG_REFS
29+ print_refs(*this, "gstreamer::Playbin::~Playbin pipeline");
30+#endif
31+
32 g_signal_handler_disconnect(pipeline, about_to_finish_handler_id);
33 g_signal_handler_disconnect(pipeline, source_setup_handler_id);
34
35 if (pipeline)
36 gst_object_unref(pipeline);
37
38- if (video_sink)
39- gst_object_unref(video_sink);
40-
41- if (audio_sink)
42- gst_object_unref(audio_sink);
43+#ifdef DEBUG_REFS
44+ print_refs(*this, "gstreamer::Playbin::~Playbin pipeline");
45+#endif
46 }
47
48 void gstreamer::Playbin::reset()
49@@ -301,8 +321,6 @@
50 "audio-sink",
51 audio_sink,
52 NULL);
53-
54- gst_object_unref(audio_sink);
55 }
56
57 if (::getenv("CORE_UBUNTU_MEDIA_SERVICE_VIDEO_SINK_NAME") != nullptr)
58@@ -318,8 +336,6 @@
59 "video-sink",
60 video_sink,
61 NULL);
62-
63- gst_object_unref(video_sink);
64 }
65 }
66
67@@ -378,17 +394,13 @@
68 /** Sets the new audio stream role on the pulsesink in playbin */
69 void gstreamer::Playbin::set_audio_stream_role(media::Player::AudioStreamRole new_audio_role)
70 {
71- GstElement *audio_sink = NULL;
72- g_object_get (pipeline, "audio-sink", &audio_sink, NULL);
73-
74 std::string role_str("props,media.role=" + get_audio_role_str(new_audio_role));
75 std::cout << "Audio stream role: " << role_str << std::endl;
76
77 GstStructure *props = gst_structure_from_string (role_str.c_str(), NULL);
78- if (audio_sink != nullptr && props != nullptr)
79+ if (audio_sink != nullptr && props != nullptr) {
80 g_object_set (audio_sink, "stream-properties", props, NULL);
81- else
82- {
83+ } else {
84 std::cerr <<
85 "Warning: couldn't set audio stream role - couldn't get audio_sink from pipeline" <<
86 std::endl;

Subscribers

People subscribed via source and target branches