Using std::shared_ptr instead of std::unique_ptr in stream data entry

Change-Id: Ib8c6f97c2329ba5b9431c301d85c1d61f89fc3d8
This commit is contained in:
Kongqun Yang 2017-02-10 15:39:58 -08:00 committed by KongQun Yang
parent 9990524f98
commit 5f6e4a1dc1
4 changed files with 19 additions and 18 deletions

View File

@ -44,12 +44,12 @@ struct StreamData {
int stream_index = -1; int stream_index = -1;
StreamDataType stream_data_type = StreamDataType::kUnknown; StreamDataType stream_data_type = StreamDataType::kUnknown;
std::unique_ptr<PeriodInfo> period_info; std::shared_ptr<PeriodInfo> period_info;
std::unique_ptr<StreamInfo> stream_info; std::shared_ptr<StreamInfo> stream_info;
std::unique_ptr<EncryptionConfig> encryption_config; std::shared_ptr<EncryptionConfig> encryption_config;
std::unique_ptr<MediaSample> media_sample; std::shared_ptr<MediaSample> media_sample;
std::unique_ptr<MediaEvent> media_event; std::shared_ptr<MediaEvent> media_event;
std::unique_ptr<SegmentInfo> segment_info; std::shared_ptr<SegmentInfo> segment_info;
}; };
/// MediaHandler is the base media processing unit. Media handlers transform /// MediaHandler is the base media processing unit. Media handlers transform
@ -111,7 +111,7 @@ class MediaHandler {
/// Dispatch the period info to downstream handlers. /// Dispatch the period info to downstream handlers.
Status DispatchPeriodInfo(int stream_index, Status DispatchPeriodInfo(int stream_index,
std::unique_ptr<PeriodInfo> period_info) { std::shared_ptr<PeriodInfo> period_info) {
std::unique_ptr<StreamData> stream_data(new StreamData); std::unique_ptr<StreamData> stream_data(new StreamData);
stream_data->stream_index = stream_index; stream_data->stream_index = stream_index;
stream_data->stream_data_type = StreamDataType::kPeriodInfo; stream_data->stream_data_type = StreamDataType::kPeriodInfo;
@ -121,7 +121,7 @@ class MediaHandler {
/// Dispatch the stream info to downstream handlers. /// Dispatch the stream info to downstream handlers.
Status DispatchStreamInfo(int stream_index, Status DispatchStreamInfo(int stream_index,
std::unique_ptr<StreamInfo> stream_info) { std::shared_ptr<StreamInfo> stream_info) {
std::unique_ptr<StreamData> stream_data(new StreamData); std::unique_ptr<StreamData> stream_data(new StreamData);
stream_data->stream_index = stream_index; stream_data->stream_index = stream_index;
stream_data->stream_data_type = StreamDataType::kStreamInfo; stream_data->stream_data_type = StreamDataType::kStreamInfo;
@ -142,7 +142,7 @@ class MediaHandler {
/// Dispatch the media sample to downstream handlers. /// Dispatch the media sample to downstream handlers.
Status DispatchMediaSample(int stream_index, Status DispatchMediaSample(int stream_index,
std::unique_ptr<MediaSample> media_sample) { std::shared_ptr<MediaSample> media_sample) {
std::unique_ptr<StreamData> stream_data(new StreamData); std::unique_ptr<StreamData> stream_data(new StreamData);
stream_data->stream_index = stream_index; stream_data->stream_index = stream_index;
stream_data->stream_data_type = StreamDataType::kMediaSample; stream_data->stream_data_type = StreamDataType::kMediaSample;
@ -152,7 +152,7 @@ class MediaHandler {
/// Dispatch the media event to downstream handlers. /// Dispatch the media event to downstream handlers.
Status DispatchMediaEvent(int stream_index, Status DispatchMediaEvent(int stream_index,
std::unique_ptr<MediaEvent> media_event) { std::shared_ptr<MediaEvent> media_event) {
std::unique_ptr<StreamData> stream_data(new StreamData); std::unique_ptr<StreamData> stream_data(new StreamData);
stream_data->stream_index = stream_index; stream_data->stream_index = stream_index;
stream_data->stream_data_type = StreamDataType::kMediaEvent; stream_data->stream_data_type = StreamDataType::kMediaEvent;
@ -162,7 +162,7 @@ class MediaHandler {
/// Dispatch the segment info to downstream handlers. /// Dispatch the segment info to downstream handlers.
Status DispatchSegmentInfo(int stream_index, Status DispatchSegmentInfo(int stream_index,
std::unique_ptr<SegmentInfo> segment_info) { std::shared_ptr<SegmentInfo> segment_info) {
std::unique_ptr<StreamData> stream_data(new StreamData); std::unique_ptr<StreamData> stream_data(new StreamData);
stream_data->stream_index = stream_index; stream_data->stream_index = stream_index;
stream_data->stream_data_type = StreamDataType::kSegmentInfo; stream_data->stream_data_type = StreamDataType::kSegmentInfo;

View File

@ -133,16 +133,17 @@ void MediaHandlerTestBase::ClearOutputStreamDataVector() {
next_handler_->clear_stream_data_vector(); next_handler_->clear_stream_data_vector();
} }
std::unique_ptr<StreamInfo> MediaHandlerTestBase::GetMockStreamInfo( std::shared_ptr<StreamInfo> MediaHandlerTestBase::GetMockStreamInfo(
Codec codec, uint32_t time_scale) { Codec codec,
uint32_t time_scale) {
if (codec >= kCodecAudio && codec < kCodecAudioMaxPlusOne) { if (codec >= kCodecAudio && codec < kCodecAudioMaxPlusOne) {
return std::unique_ptr<StreamInfo>(new AudioStreamInfo( return std::shared_ptr<StreamInfo>(new AudioStreamInfo(
kTrackId, time_scale, kDuration, codec, kCodecString, kCodecConfig, kTrackId, time_scale, kDuration, codec, kCodecString, kCodecConfig,
sizeof(kCodecConfig), kSampleBits, kNumChannels, kSamplingFrequency, sizeof(kCodecConfig), kSampleBits, kNumChannels, kSamplingFrequency,
kSeekPrerollNs, kCodecDelayNs, kMaxBitrate, kAvgBitrate, kLanguage, kSeekPrerollNs, kCodecDelayNs, kMaxBitrate, kAvgBitrate, kLanguage,
!kEncrypted)); !kEncrypted));
} else if (codec >= kCodecVideo && codec < kCodecVideoMaxPlusOne) { } else if (codec >= kCodecVideo && codec < kCodecVideoMaxPlusOne) {
return std::unique_ptr<StreamInfo>(new VideoStreamInfo( return std::shared_ptr<StreamInfo>(new VideoStreamInfo(
kTrackId, time_scale, kDuration, codec, kCodecString, kCodecConfig, kTrackId, time_scale, kDuration, codec, kCodecString, kCodecConfig,
sizeof(kCodecConfig), kWidth, kHeight, kPixelWidth, kPixelHeight, sizeof(kCodecConfig), kWidth, kHeight, kPixelWidth, kPixelHeight,
kTrickPlayRate, kNaluLengthSize, kLanguage, !kEncrypted)); kTrickPlayRate, kNaluLengthSize, kLanguage, !kEncrypted));

View File

@ -85,7 +85,7 @@ class MediaHandlerTestBase : public ::testing::Test {
MediaHandlerTestBase& operator=(const MediaHandlerTestBase&) = delete; MediaHandlerTestBase& operator=(const MediaHandlerTestBase&) = delete;
// Get a mock stream info for testing. // Get a mock stream info for testing.
std::unique_ptr<StreamInfo> GetMockStreamInfo(Codec codec, std::shared_ptr<StreamInfo> GetMockStreamInfo(Codec codec,
uint32_t time_scale); uint32_t time_scale);
// Downstream handler used in testing graph. // Downstream handler used in testing graph.

View File

@ -110,8 +110,8 @@ class ChunkingHandler : public MediaHandler {
// Current subsegment index, useful to determine where to do chunking. // Current subsegment index, useful to determine where to do chunking.
int64_t current_subsegment_index_ = -1; int64_t current_subsegment_index_ = -1;
std::vector<std::unique_ptr<SegmentInfo>> segment_info_; std::vector<std::shared_ptr<SegmentInfo>> segment_info_;
std::vector<std::unique_ptr<SegmentInfo>> subsegment_info_; std::vector<std::shared_ptr<SegmentInfo>> subsegment_info_;
std::vector<uint32_t> time_scales_; std::vector<uint32_t> time_scales_;
// The end timestamp of the last dispatched sample. // The end timestamp of the last dispatched sample.
std::vector<int64_t> last_sample_end_timestamps_; std::vector<int64_t> last_sample_end_timestamps_;