| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/filters/ffmpeg_demuxer.h" | 5 #include "media/filters/ffmpeg_demuxer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 959 // Estimate the start time for each stream by looking through the packets | 959 // Estimate the start time for each stream by looking through the packets |
| 960 // buffered during avformat_find_stream_info(). These values will be | 960 // buffered during avformat_find_stream_info(). These values will be |
| 961 // considered later when determining the actual stream start time. | 961 // considered later when determining the actual stream start time. |
| 962 // | 962 // |
| 963 // These packets haven't been completely processed yet, so only look through | 963 // These packets haven't been completely processed yet, so only look through |
| 964 // these values if the AVFormatContext has a valid start time. | 964 // these values if the AVFormatContext has a valid start time. |
| 965 // | 965 // |
| 966 // If no estimate is found, the stream entry will be kInfiniteDuration(). | 966 // If no estimate is found, the stream entry will be kInfiniteDuration(). |
| 967 std::vector<base::TimeDelta> start_time_estimates(format_context->nb_streams, | 967 std::vector<base::TimeDelta> start_time_estimates(format_context->nb_streams, |
| 968 kInfiniteDuration()); | 968 kInfiniteDuration()); |
| 969 const AVFormatInternal* internal = format_context->internal; | |
| 970 if (internal && internal->packet_buffer && | |
| 971 format_context->start_time != static_cast<int64>(AV_NOPTS_VALUE)) { | |
| 972 struct AVPacketList* packet_buffer = internal->packet_buffer; | |
| 973 while (packet_buffer != internal->packet_buffer_end) { | |
| 974 DCHECK_LT(static_cast<size_t>(packet_buffer->pkt.stream_index), | |
| 975 start_time_estimates.size()); | |
| 976 const AVStream* stream = | |
| 977 format_context->streams[packet_buffer->pkt.stream_index]; | |
| 978 if (packet_buffer->pkt.pts != static_cast<int64>(AV_NOPTS_VALUE)) { | |
| 979 const base::TimeDelta packet_pts = | |
| 980 ConvertFromTimeBase(stream->time_base, packet_buffer->pkt.pts); | |
| 981 if (packet_pts < start_time_estimates[stream->index]) | |
| 982 start_time_estimates[stream->index] = packet_pts; | |
| 983 } | |
| 984 packet_buffer = packet_buffer->next; | |
| 985 } | |
| 986 } | |
| 987 | 969 |
| 988 AVStream* audio_stream = NULL; | 970 AVStream* audio_stream = NULL; |
| 989 AudioDecoderConfig audio_config; | 971 AudioDecoderConfig audio_config; |
| 990 | 972 |
| 991 AVStream* video_stream = NULL; | 973 AVStream* video_stream = NULL; |
| 992 VideoDecoderConfig video_config; | 974 VideoDecoderConfig video_config; |
| 993 | 975 |
| 994 // If available, |start_time_| will be set to the lowest stream start time. | 976 // If available, |start_time_| will be set to the lowest stream start time. |
| 995 start_time_ = kInfiniteDuration(); | 977 start_time_ = kInfiniteDuration(); |
| 996 | 978 |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1457 | 1439 |
| 1458 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { | 1440 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { |
| 1459 DCHECK(task_runner_->BelongsToCurrentThread()); | 1441 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 1460 for (const auto& stream : streams_) { // |stream| is a ref to a pointer. | 1442 for (const auto& stream : streams_) { // |stream| is a ref to a pointer. |
| 1461 if (stream) | 1443 if (stream) |
| 1462 stream->SetLiveness(liveness); | 1444 stream->SetLiveness(liveness); |
| 1463 } | 1445 } |
| 1464 } | 1446 } |
| 1465 | 1447 |
| 1466 } // namespace media | 1448 } // namespace media |
| OLD | NEW |