| OLD | NEW |
| (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_state.mojom.h" |
| 13 #include "mojo/services/media/common/interfaces/media_transport.mojom.h" |
| 14 #include "services/media/framework/models/active_sink.h" |
| 15 #include "services/media/framework_mojo/mojo_allocator.h" |
| 16 |
| 17 namespace mojo { |
| 18 namespace media { |
| 19 |
| 20 // Implements MediaPullModeProducer to forward a stream across mojo. |
| 21 class MojoPullModeProducer : |
| 22 public MediaPullModeProducer, |
| 23 public ActiveSink { |
| 24 public: |
| 25 static std::shared_ptr<MojoPullModeProducer> Create() { |
| 26 return std::shared_ptr<MojoPullModeProducer>(new MojoPullModeProducer()); |
| 27 } |
| 28 |
| 29 ~MojoPullModeProducer() override; |
| 30 |
| 31 // Adds a binding. |
| 32 void AddBinding(InterfaceRequest<MediaPullModeProducer> producer); |
| 33 |
| 34 // MediaPullModeProducer implementation. |
| 35 void GetBuffer(const GetBufferCallback& callback) override; |
| 36 |
| 37 void PullPacket( |
| 38 MediaPacketPtr to_release, |
| 39 const PullPacketCallback& callback) override; |
| 40 |
| 41 void ReleasePacket(MediaPacketPtr to_release) override; |
| 42 |
| 43 // ActiveSink implementation. |
| 44 PayloadAllocator* allocator() override; |
| 45 |
| 46 void SetDemandCallback(const DemandCallback& demand_callback) override; |
| 47 |
| 48 void Prime() override; |
| 49 |
| 50 Demand SupplyPacket(PacketPtr packet) override; |
| 51 |
| 52 private: |
| 53 MojoPullModeProducer(); |
| 54 |
| 55 // Handles as many pending pulls as possible. |
| 56 // MUST BE CALLED WITH lock_ TAKEN. |
| 57 void HandlePendingPullsUnsafe(); |
| 58 |
| 59 // Attempts to handle a pull and indicates whether it was handled. |
| 60 // MUST BE CALLED WITH lock_ TAKEN. |
| 61 bool MaybeHandlePullUnsafe(const PullPacketCallback& callback); |
| 62 |
| 63 // Runs the callback with a new MediaPacket created from the given Packet. |
| 64 // MUST BE CALLED WITH lock_ TAKEN. |
| 65 void HandlePullWithPacketUnsafe( |
| 66 const PullPacketCallback& callback, |
| 67 PacketPtr packet); |
| 68 |
| 69 // Creates a MediaPacket from a Packet. |
| 70 MediaPacketPtr CreateMediaPacket(const PacketPtr& packet); |
| 71 |
| 72 BindingSet<MediaPullModeProducer> bindings_; |
| 73 |
| 74 DemandCallback demand_callback_; |
| 75 |
| 76 // Allocates from the shared buffer. |
| 77 MojoAllocator mojo_allocator_; |
| 78 |
| 79 mutable base::Lock lock_; |
| 80 // THE FIELDS BELOW SHOULD ONLY BE ACCESSED WITH lock_ TAKEN. |
| 81 MediaState state_; |
| 82 Demand demand_; |
| 83 int64_t presentation_time_; |
| 84 |
| 85 // pending_pulls_ contains the callbacks for the pull requests that have yet |
| 86 // to be satisfied. unreleased_packets_ contains the packets that have been |
| 87 // delivered via pull but have not yet been released. cached_packet_ is a |
| 88 // packet waiting for a pull (we keep one ready so we can be preparing a |
| 89 // packet between pulls). If cached_packet_ isn't nullptr, pending_pulls_ |
| 90 // should be empty. We signal positive demand when cached_packet_ is nullptr |
| 91 // and negative demand when it isn't. |
| 92 std::deque<PullPacketCallback> pending_pulls_; |
| 93 std::deque<PacketPtr> unreleased_packets_; |
| 94 PacketPtr cached_packet_; |
| 95 // THE FIELDS ABOVE SHOULD ONLY BE ACCESSED WITH lock_ TAKEN. |
| 96 }; |
| 97 |
| 98 } // namespace media |
| 99 } // namespace mojo |
| 100 |
| 101 #endif // SERVICES_MEDIA_FRAMEWORK_MOJO_MOJO_PULL_MODE_PRODUCER_H_ |
| OLD | NEW |