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  Status ProcessCachedStreamData(
54  size_t output_stream_index,
55  std::deque<std::shared_ptr<StreamData>>* cached_stream_data);
56 
57  // Process a single stream data. Depending on the stream data type, some
58  // information needs to be updated.
59  // Decoding timestamp for current key media sample. It is used for calculating
60  // the duration of previous key media sample, to make sure there is no gap
61  // between two key media samples.
62  Status ProcessOneStreamData(size_t output_stream_index,
63  const std::shared_ptr<StreamData>& stream_data);
64 
65  const TrickPlayOptions trick_play_options_;
66 
67  TrickPlayHandler(const TrickPlayHandler&) = delete;
68  TrickPlayHandler& operator=(const TrickPlayHandler&) = delete;
69 
71  uint32_t total_key_frames_ = 0;
72 
73  // End timestamp of the previous processed media_sample, which is |dts| +
74  // |duration|. The duration of key frame in trick play stream is updated based
75  // on this timestamp.
76  int64_t prev_sample_end_timestamp_ = 0;
77 
78  // The data in output streams should be in the same order as in the input
79  // stream. Cache the stream data before next key frame so that we can
80  // determine the duration for the current key frame. Since one key frame may
81  // be dispatched to different trick play stream, each trick play stream need
82  // its own queue to handle the synchronization.
83  // TODO(hmchen): Use one queue and multiple iterators, instead of multiple
84  // queues.
85  std::vector<std::deque<std::shared_ptr<StreamData>>> cached_stream_data_;
86 };
87 
88 } // namespace media
89 } // namespace shaka
90 
91 #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