DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
trick_play_handler.h
1 // Copyright 2017 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #ifndef PACKAGER_MEDIA_BASE_TRICK_PLAY_HANDLER_H_
8 #define PACKAGER_MEDIA_BASE_TRICK_PLAY_HANDLER_H_
9 
10 #include "packager/media/base/media_handler.h"
11 
12 namespace shaka {
13 namespace media {
14 
23  std::vector<int16_t> trick_play_rates;
24 };
25 
28 // The stream data in trick play stream is not a simple duplicate. Some
29 // information need to be updated, including trick_play_rate in
30 // VideoStreamInfo, the duration in MediaSample (which makes sure there is no
31 // gap between the media sample dts). Since the duration information can be
32 // determined after getting the next media sample, a queue is used to cache the
33 // input stream data before the next key frame.
35  public:
36  explicit TrickPlayHandler(const TrickPlayOptions& trick_play_options);
37  ~TrickPlayHandler() override;
38 
39  protected:
42  Status InitializeInternal() override;
43  Status Process(std::unique_ptr<StreamData> stream_data) override;
44  bool ValidateOutputStreamIndex(size_t stream_index) const override;
45  Status OnFlushRequest(size_t input_stream_index) override;
47 
48  private:
49  friend class TrickPlayHandlerTest;
50 
51  // Process the cached stream data for one trick play stream.
52  // The cached data is dispatched to the |output_stream_index|.
53  // The |current_dts| is for updating the duration of key frames,
54  // so that there is no gap between consecutive key frames. When
55  // |current_dts| = -1, the original duration of the key frame is used.
56  Status ProcessCachedStreamData(
57  int output_stream_index,
58  std::deque<std::shared_ptr<StreamData>>* cached_stream_data);
59 
60  // Process a single stream data. Depending on the stream data type, some
61  // information needs to be updated.
62  // Decoding timestamp for current key media sample. It is used for calculating
63  // the duration of previous key media sample, to make sure there is no gap
64  // between two key media samples.
65  Status ProcessOneStreamData(int output_stream_index,
66  const std::shared_ptr<StreamData>& stream_data);
67 
68  const TrickPlayOptions trick_play_options_;
69 
70  TrickPlayHandler(const TrickPlayHandler&) = delete;
71  TrickPlayHandler& operator=(const TrickPlayHandler&) = delete;
72 
74  uint32_t total_key_frames_ = 0;
75 
76  // End timestamp of the previous processed media_sample, which is |dts| +
77  // |duration|. The duration of key frame in trick play stream is updated based
78  // on this timestamp.
79  int64_t prev_sample_end_timestamp_ = 0;
80 
81  // The data in output streams should be in the same order as in the input
82  // stream. Cache the stream data before next key frame so that we can
83  // determine the duration for the current key frame. Since one key frame may
84  // be dispatched to different trick play stream, each trick play stream need
85  // its own queue to handle the synchronization.
86  // TODO(hmchen): Use one queue and multiple iterators, instead of multiple
87  // queues.
88  std::vector<std::deque<std::shared_ptr<StreamData>>> cached_stream_data_;
89 };
90 
91 } // namespace media
92 } // namespace shaka
93 
94 #endif // PACKAGER_MEDIA_BASE_TRICK_PLAY_HANDLER_H_
bool ValidateOutputStreamIndex(size_t stream_index) const override
Validate if the stream at the specified index actually exists.
Status OnFlushRequest(size_t input_stream_index) override
Event handler for flush request at the specific input stream index.
std::vector< int16_t > trick_play_rates
Status Process(std::unique_ptr< StreamData > stream_data) override