Shaka Packager SDK
Loading...
Searching...
No Matches
chunking_handler.h
1// Copyright 2017 Google LLC. 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_CHUNKING_CHUNKING_HANDLER_
8#define PACKAGER_MEDIA_CHUNKING_CHUNKING_HANDLER_
9
10#include <atomic>
11#include <optional>
12#include <queue>
13
14#include <absl/log/log.h>
15
16#include <packager/chunking_params.h>
17#include <packager/media/base/media_handler.h>
18
19namespace shaka {
20namespace media {
21
41 public:
42 explicit ChunkingHandler(const ChunkingParams& chunking_params);
43 ~ChunkingHandler() override = default;
44
45 protected:
48 Status InitializeInternal() override;
49 Status Process(std::unique_ptr<StreamData> stream_data) override;
50 Status OnFlushRequest(size_t input_stream_index) override;
52
53 private:
54 friend class ChunkingHandlerTest;
55
56 ChunkingHandler(const ChunkingHandler&) = delete;
57 ChunkingHandler& operator=(const ChunkingHandler&) = delete;
58
59 Status OnStreamInfo(std::shared_ptr<const StreamInfo> info);
60 Status OnCueEvent(std::shared_ptr<const CueEvent> event);
61 Status OnMediaSample(std::shared_ptr<const MediaSample> sample);
62
63 Status EndSegmentIfStarted();
64 Status EndSubsegmentIfStarted() const;
65
66 bool IsSubsegmentEnabled() {
67 return subsegment_duration_ > 0 &&
68 subsegment_duration_ != segment_duration_;
69 }
70
71 const ChunkingParams chunking_params_;
72
73 // Segment and subsegment duration in stream's time scale.
74 int64_t segment_duration_ = 0;
75 int64_t subsegment_duration_ = 0;
76
77 // Segment number that keeps monotically increasing.
78 // Set to start_segment_number in constructor.
79 int64_t segment_number_ = 1;
80
81 // Current segment index, useful to determine where to do chunking.
82 int64_t current_segment_index_ = -1;
83
84 // Current subsegment index, useful to determine where to do chunking.
85 int64_t current_subsegment_index_ = -1;
86
87 std::optional<int64_t> segment_start_time_;
88 std::optional<int64_t> subsegment_start_time_;
89 int64_t max_segment_time_ = 0;
90 int32_t time_scale_ = 0;
91
92 // The offset is applied to sample timestamps so a full segment is generated
93 // after cue points.
94 int64_t cue_offset_ = 0;
95};
96
97} // namespace media
98} // namespace shaka
99
100#endif // PACKAGER_MEDIA_CHUNKING_CHUNKING_HANDLER_
Status Process(std::unique_ptr< StreamData > stream_data) override
Status OnFlushRequest(size_t input_stream_index) override
Event handler for flush request at the specific input stream index.
All the methods that are virtual are virtual for mocking.