Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(453)

Side by Side Diff: services/media/framework_mojo/mojo_pull_mode_producer.h

Issue 2097953002: Motown: Rename MediaProducer/Consumer to MediaPacketProducer/Consumer (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Fixed #ifndef guards Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef SERVICES_MEDIA_FRAMEWORK_MOJO_MOJO_PULL_MODE_PRODUCER_H_
6 #define SERVICES_MEDIA_FRAMEWORK_MOJO_MOJO_PULL_MODE_PRODUCER_H_
7
8 #include <deque>
9
10 #include "base/synchronization/lock.h"
11 #include "mojo/common/binding_set.h"
12 #include "mojo/services/media/common/interfaces/media_transport.mojom.h"
13 #include "services/media/framework/models/active_sink.h"
14 #include "services/media/framework_mojo/mojo_allocator.h"
15
16 namespace mojo {
17 namespace media {
18
19 // Implements MediaPullModeProducer to forward a stream across mojo.
20 class MojoPullModeProducer : public MediaPullModeProducer, public ActiveSink {
21 public:
22 static std::shared_ptr<MojoPullModeProducer> Create() {
23 return std::shared_ptr<MojoPullModeProducer>(new MojoPullModeProducer());
24 }
25
26 ~MojoPullModeProducer() override;
27
28 // Adds a binding.
29 void AddBinding(InterfaceRequest<MediaPullModeProducer> producer);
30
31 // MediaPullModeProducer implementation.
32 void GetBuffer(const GetBufferCallback& callback) override;
33
34 void PullPacket(MediaPacketPtr to_release,
35 const PullPacketCallback& callback) override;
36
37 void ReleasePacket(MediaPacketPtr to_release) override;
38
39 // ActiveSink implementation.
40 PayloadAllocator* allocator() override;
41
42 void SetDemandCallback(const DemandCallback& demand_callback) override;
43
44 Demand SupplyPacket(PacketPtr packet) override;
45
46 private:
47 MojoPullModeProducer();
48
49 // Handles as many pending pulls as possible.
50 // MUST BE CALLED WITH lock_ TAKEN.
51 void HandlePendingPullsUnsafe();
52
53 // Attempts to handle a pull and indicates whether it was handled.
54 // MUST BE CALLED WITH lock_ TAKEN.
55 bool MaybeHandlePullUnsafe(const PullPacketCallback& callback);
56
57 // Runs the callback with a new MediaPacket created from the given Packet.
58 // MUST BE CALLED WITH lock_ TAKEN.
59 void HandlePullWithPacketUnsafe(const PullPacketCallback& callback,
60 PacketPtr packet);
61
62 // Creates a MediaPacket from a Packet.
63 MediaPacketPtr CreateMediaPacket(const PacketPtr& packet);
64
65 BindingSet<MediaPullModeProducer> bindings_;
66
67 DemandCallback demand_callback_;
68
69 // Allocates from the shared buffer.
70 MojoAllocator mojo_allocator_;
71
72 mutable base::Lock lock_;
73 // THE FIELDS BELOW SHOULD ONLY BE ACCESSED WITH lock_ TAKEN.
74 Demand demand_;
75 int64_t pts_;
76
77 // pending_pulls_ contains the callbacks for the pull requests that have yet
78 // to be satisfied. unreleased_packets_ contains the packets that have been
79 // delivered via pull but have not yet been released. cached_packet_ is a
80 // packet waiting for a pull (we keep one ready so we can be preparing a
81 // packet between pulls). If cached_packet_ isn't nullptr, pending_pulls_
82 // should be empty. We signal positive demand when cached_packet_ is nullptr
83 // and negative demand when it isn't.
84 std::deque<PullPacketCallback> pending_pulls_;
85 std::deque<PacketPtr> unreleased_packets_;
86 PacketPtr cached_packet_;
87 // THE FIELDS ABOVE SHOULD ONLY BE ACCESSED WITH lock_ TAKEN.
88 };
89
90 } // namespace media
91 } // namespace mojo
92
93 #endif // SERVICES_MEDIA_FRAMEWORK_MOJO_MOJO_PULL_MODE_PRODUCER_H_
OLDNEW
« no previous file with comments | « services/media/framework_mojo/mojo_producer.cc ('k') | services/media/framework_mojo/mojo_pull_mode_producer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698