Music Hub  ..
A session-wide music playback service
hybris_recorder_observer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright © 2014 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Thomas Voß <thomas.voss@canonical.com>
17  */
18 
20 
21 #include <hybris/media/media_recorder_layer.h>
22 
23 namespace media = core::ubuntu::media;
24 
26 {
27  struct Holder
28  {
29  std::weak_ptr<media::HybrisRecorderObserver::Private> wp;
30  };
31 
32  // The fringe that we hand over to hybris.
33  static void on_media_recording_state_changed(bool started, void* context)
34  {
35  if (auto holder = static_cast<Holder*>(context))
36  {
37  if (auto sp = holder->wp.lock())
38  {
39  sp->recording_state = started ? media::RecordingState::started : media::RecordingState::stopped;
40  }
41  }
42  }
43 
44  // TODO: We have no way of freeing the observer and thus leak
45  // an instance here.
46  MediaRecorderObserver* observer
47  {
48  android_media_recorder_observer_new()
49  };
50 
51  core::Property<media::RecordingState> recording_state
52  {
54  };
55 
56  Holder* holder
57  {
58  nullptr
59  };
60 };
61 
62 media::HybrisRecorderObserver::HybrisRecorderObserver() : d{new Private{}}
63 {
64  android_media_recorder_observer_set_cb(
65  d->observer,
67  d->holder = new Private::Holder{d});
68 }
69 
71 {
72  // We first reset the context of the callback.
73  android_media_recorder_observer_set_cb(
74  d->observer,
76  nullptr);
77 
78  delete d->holder;
79 }
80 
81 const core::Property<media::RecordingState>& media::HybrisRecorderObserver::recording_state() const
82 {
83  return d->recording_state;
84 }
85 
87 {
89 }
core::Property< media::RecordingState > recording_state
static RecorderObserver::Ptr create()
static void on_media_recording_state_changed(bool started, void *context)
std::shared_ptr< RecorderObserver > Ptr
std::weak_ptr< media::HybrisRecorderObserver::Private > wp
const core::Property< RecordingState > & recording_state() const override