Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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_AUDIO_AUDIO_PIPE_H_ | |
| 6 #define SERVICES_MEDIA_AUDIO_AUDIO_PIPE_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "mojo/services/media/common/cpp/linear_transform.h" | |
| 12 #include "services/media/audio/fwd_decls.h" | |
| 13 #include "services/media/common/media_pipe_base.h" | |
| 14 | |
| 15 namespace mojo { | |
| 16 namespace media { | |
| 17 namespace audio { | |
| 18 | |
| 19 class AudioPipe : public MediaPipeBase { | |
| 20 public: | |
| 21 class AudioPacketRef; | |
| 22 using AudioPacketRefPtr = std::shared_ptr<AudioPacketRef>; | |
| 23 using MediaPacketStatePtr = MediaPipeBase::MediaPacketStatePtr; | |
| 24 | |
| 25 class AudioPacketRef { | |
| 26 public: | |
| 27 struct Region { | |
| 28 Region(const void* b, uint32_t ffl) : base(b), frac_frame_len(ffl) {} | |
| 29 const void* base; | |
| 30 uint32_t frac_frame_len; | |
| 31 }; | |
| 32 | |
| 33 ~AudioPacketRef(); | |
| 34 | |
| 35 const MediaPacketPtr& GetPacket() const { return state_->GetPacket(); } | |
| 36 void SetResult(MediaResult result) { return state_->SetResult(result); } | |
| 37 | |
| 38 // Accessors for starting and ending presentation time stamps expressed in | |
| 39 // units of audio frames (note, not media time), as signed 51.12 fixed point | |
| 40 // integers (see AudioTrackImpl:PTS_FRACTIONAL_BITS). At 192KHz, this | |
| 41 // allows for ~372.7 years of usable range when starting from a media time | |
| 42 // of 0. | |
|
jeffbrown
2015/11/04 23:43:33
Might be good to define a struct for manipulating
johngro
2015/11/06 02:20:25
I'm not sure that a struct is what you want here (
| |
| 43 // | |
| 44 // AudioPackets consumed by the AudioServer are all expected to have | |
| 45 // explicit presentation time stamps. If packets sent by the user are | |
| 46 // missing timestamps, appropriate timestamps will be synthesized at this | |
| 47 // point in the pipeline. | |
| 48 // | |
| 49 // Note, the start pts is the time at which the first frame of audio in the | |
| 50 // packet should be presented. The end_pts is the time at which the frame | |
| 51 // after the final frame in the packet would be presented. | |
| 52 // | |
| 53 // TODO(johngro): Reconsider this. It may be best to keep things expressed | |
| 54 // simply in media time instead of converting to fractional units of track | |
| 55 // frames. If/when outputs move away from a single fixed step size for | |
| 56 // output sampling, it will probably be best to just convert this back to | |
| 57 // media time. | |
| 58 const int64_t& start_pts() const { return start_pts_; } | |
| 59 const int64_t& end_pts() const { return end_pts_; } | |
| 60 | |
| 61 // Accessor for the regions in the shared buffer which contain the actual | |
| 62 // sample data. | |
| 63 const std::vector<Region>& regions() const { return regions_; } | |
| 64 | |
| 65 private: | |
| 66 friend class AudioPipe; | |
| 67 AudioPacketRef(MediaPacketStatePtr state, | |
| 68 AudioServerImpl* server, | |
| 69 std::vector<Region>&& regions, | |
| 70 int64_t start_pts, | |
| 71 int64_t end_pts); | |
| 72 | |
| 73 MediaPacketStatePtr state_; | |
| 74 AudioServerImpl* server_; | |
| 75 | |
| 76 std::vector<Region> regions_; | |
| 77 int64_t start_pts_; | |
| 78 int64_t end_pts_; | |
| 79 }; | |
| 80 | |
| 81 AudioPipe(AudioTrackImpl* owner, AudioServerImpl* server); | |
| 82 ~AudioPipe() override; | |
| 83 | |
| 84 protected: | |
| 85 void OnPacketReceived(MediaPacketStatePtr state) override; | |
| 86 void OnFlushRequested(const FlushCallback& cbk) override; | |
| 87 | |
| 88 private: | |
| 89 AudioTrackImpl* owner_; | |
| 90 AudioServerImpl* server_; | |
| 91 | |
| 92 // State used for timestamp interpolation | |
| 93 bool next_pts_known_ = 0; | |
| 94 int64_t next_pts_; | |
| 95 }; | |
| 96 | |
| 97 } // namespace audio | |
| 98 } // namespace media | |
| 99 } // namespace mojo | |
| 100 | |
| 101 #endif // SERVICES_MEDIA_AUDIO_AUDIO_PIPE_H_ | |
| OLD | NEW |