OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/formats/mp2t/mp2t_stream_parser.h" | 5 #include "media/formats/mp2t/mp2t_stream_parser.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
9 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
10 #include "media/base/stream_parser_buffer.h" | 12 #include "media/base/stream_parser_buffer.h" |
11 #include "media/base/text_track_config.h" | 13 #include "media/base/text_track_config.h" |
12 #include "media/base/timestamp_constants.h" | 14 #include "media/base/timestamp_constants.h" |
13 #include "media/formats/mp2t/es_parser.h" | 15 #include "media/formats/mp2t/es_parser.h" |
14 #include "media/formats/mp2t/es_parser_adts.h" | 16 #include "media/formats/mp2t/es_parser_adts.h" |
15 #include "media/formats/mp2t/es_parser_h264.h" | 17 #include "media/formats/mp2t/es_parser_h264.h" |
16 #include "media/formats/mp2t/es_parser_mpeg1audio.h" | 18 #include "media/formats/mp2t/es_parser_mpeg1audio.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 67 |
66 int pid_; | 68 int pid_; |
67 PidType pid_type_; | 69 PidType pid_type_; |
68 scoped_ptr<TsSection> section_parser_; | 70 scoped_ptr<TsSection> section_parser_; |
69 | 71 |
70 bool enable_; | 72 bool enable_; |
71 | 73 |
72 int continuity_counter_; | 74 int continuity_counter_; |
73 }; | 75 }; |
74 | 76 |
75 PidState::PidState(int pid, PidType pid_type, | 77 PidState::PidState(int pid, |
| 78 PidType pid_type, |
76 scoped_ptr<TsSection> section_parser) | 79 scoped_ptr<TsSection> section_parser) |
77 : pid_(pid), | 80 : pid_(pid), |
78 pid_type_(pid_type), | 81 pid_type_(pid_type), |
79 section_parser_(section_parser.Pass()), | 82 section_parser_(std::move(section_parser)), |
80 enable_(false), | 83 enable_(false), |
81 continuity_counter_(-1) { | 84 continuity_counter_(-1) { |
82 DCHECK(section_parser_); | 85 DCHECK(section_parser_); |
83 } | 86 } |
84 | 87 |
85 bool PidState::PushTsPacket(const TsPacket& ts_packet) { | 88 bool PidState::PushTsPacket(const TsPacket& ts_packet) { |
86 DCHECK_EQ(ts_packet.pid(), pid_); | 89 DCHECK_EQ(ts_packet.pid(), pid_); |
87 | 90 |
88 // The current PID is not part of the PID filter, | 91 // The current PID is not part of the PID filter, |
89 // just discard the incoming TS packet. | 92 // just discard the incoming TS packet. |
90 if (!enable_) | 93 if (!enable_) |
91 return true; | 94 return true; |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 | 277 |
275 // Parse the section. | 278 // Parse the section. |
276 std::map<int, PidState*>::iterator it = pids_.find(ts_packet->pid()); | 279 std::map<int, PidState*>::iterator it = pids_.find(ts_packet->pid()); |
277 if (it == pids_.end() && | 280 if (it == pids_.end() && |
278 ts_packet->pid() == TsSection::kPidPat) { | 281 ts_packet->pid() == TsSection::kPidPat) { |
279 // Create the PAT state here if needed. | 282 // Create the PAT state here if needed. |
280 scoped_ptr<TsSection> pat_section_parser( | 283 scoped_ptr<TsSection> pat_section_parser( |
281 new TsSectionPat( | 284 new TsSectionPat( |
282 base::Bind(&Mp2tStreamParser::RegisterPmt, | 285 base::Bind(&Mp2tStreamParser::RegisterPmt, |
283 base::Unretained(this)))); | 286 base::Unretained(this)))); |
284 scoped_ptr<PidState> pat_pid_state( | 287 scoped_ptr<PidState> pat_pid_state(new PidState( |
285 new PidState(ts_packet->pid(), PidState::kPidPat, | 288 ts_packet->pid(), PidState::kPidPat, std::move(pat_section_parser))); |
286 pat_section_parser.Pass())); | |
287 pat_pid_state->Enable(); | 289 pat_pid_state->Enable(); |
288 it = pids_.insert( | 290 it = pids_.insert( |
289 std::pair<int, PidState*>(ts_packet->pid(), | 291 std::pair<int, PidState*>(ts_packet->pid(), |
290 pat_pid_state.release())).first; | 292 pat_pid_state.release())).first; |
291 } | 293 } |
292 | 294 |
293 if (it != pids_.end()) { | 295 if (it != pids_.end()) { |
294 if (!it->second->PushTsPacket(*ts_packet)) | 296 if (!it->second->PushTsPacket(*ts_packet)) |
295 return false; | 297 return false; |
296 } else { | 298 } else { |
(...skipping 26 matching lines...) Expand all Loading... |
323 } | 325 } |
324 } | 326 } |
325 | 327 |
326 // Create the PMT state here if needed. | 328 // Create the PMT state here if needed. |
327 DVLOG(1) << "Create a new PMT parser"; | 329 DVLOG(1) << "Create a new PMT parser"; |
328 scoped_ptr<TsSection> pmt_section_parser( | 330 scoped_ptr<TsSection> pmt_section_parser( |
329 new TsSectionPmt( | 331 new TsSectionPmt( |
330 base::Bind(&Mp2tStreamParser::RegisterPes, | 332 base::Bind(&Mp2tStreamParser::RegisterPes, |
331 base::Unretained(this), pmt_pid))); | 333 base::Unretained(this), pmt_pid))); |
332 scoped_ptr<PidState> pmt_pid_state( | 334 scoped_ptr<PidState> pmt_pid_state( |
333 new PidState(pmt_pid, PidState::kPidPmt, pmt_section_parser.Pass())); | 335 new PidState(pmt_pid, PidState::kPidPmt, std::move(pmt_section_parser))); |
334 pmt_pid_state->Enable(); | 336 pmt_pid_state->Enable(); |
335 pids_.insert(std::pair<int, PidState*>(pmt_pid, pmt_pid_state.release())); | 337 pids_.insert(std::pair<int, PidState*>(pmt_pid, pmt_pid_state.release())); |
336 } | 338 } |
337 | 339 |
338 void Mp2tStreamParser::RegisterPes(int pmt_pid, | 340 void Mp2tStreamParser::RegisterPes(int pmt_pid, |
339 int pes_pid, | 341 int pes_pid, |
340 int stream_type) { | 342 int stream_type) { |
341 // TODO(damienv): check there is no mismatch if the entry already exists. | 343 // TODO(damienv): check there is no mismatch if the entry already exists. |
342 DVLOG(1) << "RegisterPes:" | 344 DVLOG(1) << "RegisterPes:" |
343 << " pes_pid=" << pes_pid | 345 << " pes_pid=" << pes_pid |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 pes_pid), | 379 pes_pid), |
378 media_log_)); | 380 media_log_)); |
379 is_audio = true; | 381 is_audio = true; |
380 } else { | 382 } else { |
381 return; | 383 return; |
382 } | 384 } |
383 | 385 |
384 // Create the PES state here. | 386 // Create the PES state here. |
385 DVLOG(1) << "Create a new PES state"; | 387 DVLOG(1) << "Create a new PES state"; |
386 scoped_ptr<TsSection> pes_section_parser( | 388 scoped_ptr<TsSection> pes_section_parser( |
387 new TsSectionPes(es_parser.Pass(), ×tamp_unroller_)); | 389 new TsSectionPes(std::move(es_parser), ×tamp_unroller_)); |
388 PidState::PidType pid_type = | 390 PidState::PidType pid_type = |
389 is_audio ? PidState::kPidAudioPes : PidState::kPidVideoPes; | 391 is_audio ? PidState::kPidAudioPes : PidState::kPidVideoPes; |
390 scoped_ptr<PidState> pes_pid_state( | 392 scoped_ptr<PidState> pes_pid_state( |
391 new PidState(pes_pid, pid_type, pes_section_parser.Pass())); | 393 new PidState(pes_pid, pid_type, std::move(pes_section_parser))); |
392 pids_.insert(std::pair<int, PidState*>(pes_pid, pes_pid_state.release())); | 394 pids_.insert(std::pair<int, PidState*>(pes_pid, pes_pid_state.release())); |
393 | 395 |
394 // A new PES pid has been added, the PID filter might change. | 396 // A new PES pid has been added, the PID filter might change. |
395 UpdatePidFilter(); | 397 UpdatePidFilter(); |
396 } | 398 } |
397 | 399 |
398 void Mp2tStreamParser::UpdatePidFilter() { | 400 void Mp2tStreamParser::UpdatePidFilter() { |
399 // Applies the HLS rule to select the default audio/video PIDs: | 401 // Applies the HLS rule to select the default audio/video PIDs: |
400 // select the audio/video streams with the lowest PID. | 402 // select the audio/video streams with the lowest PID. |
401 // TODO(damienv): this can be changed when the StreamParser interface | 403 // TODO(damienv): this can be changed when the StreamParser interface |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 // so that buffers with the same config can be added later on. | 644 // so that buffers with the same config can be added later on. |
643 BufferQueueWithConfig queue_with_config( | 645 BufferQueueWithConfig queue_with_config( |
644 true, last_audio_config, last_video_config); | 646 true, last_audio_config, last_video_config); |
645 buffer_queue_chain_.push_back(queue_with_config); | 647 buffer_queue_chain_.push_back(queue_with_config); |
646 | 648 |
647 return true; | 649 return true; |
648 } | 650 } |
649 | 651 |
650 } // namespace mp2t | 652 } // namespace mp2t |
651 } // namespace media | 653 } // namespace media |
OLD | NEW |