Chromium Code Reviews| 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 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/callback_helpers.h" | 13 #include "base/callback_helpers.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/message_loop/message_loop_proxy.h" | 15 #include "base/message_loop/message_loop_proxy.h" |
| 16 #include "base/metrics/sparse_histogram.h" | 16 #include "base/metrics/sparse_histogram.h" |
| 17 #include "base/strings/string_number_conversions.h" | |
| 17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 18 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 19 #include "base/sys_byteorder.h" | 20 #include "base/sys_byteorder.h" |
| 20 #include "base/task_runner_util.h" | 21 #include "base/task_runner_util.h" |
| 21 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 22 #include "media/base/audio_decoder_config.h" | 23 #include "media/base/audio_decoder_config.h" |
| 23 #include "media/base/bind_to_current_loop.h" | 24 #include "media/base/bind_to_current_loop.h" |
| 24 #include "media/base/decoder_buffer.h" | 25 #include "media/base/decoder_buffer.h" |
| 25 #include "media/base/decrypt_config.h" | 26 #include "media/base/decrypt_config.h" |
| 26 #include "media/base/limits.h" | 27 #include "media/base/limits.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 task_runner_(base::MessageLoopProxy::current()), | 91 task_runner_(base::MessageLoopProxy::current()), |
| 91 stream_(stream), | 92 stream_(stream), |
| 92 type_(UNKNOWN), | 93 type_(UNKNOWN), |
| 93 end_of_stream_(false), | 94 end_of_stream_(false), |
| 94 last_packet_timestamp_(kNoTimestamp()), | 95 last_packet_timestamp_(kNoTimestamp()), |
| 95 bitstream_converter_enabled_(false), | 96 bitstream_converter_enabled_(false), |
| 96 fixup_negative_ogg_timestamps_(false) { | 97 fixup_negative_ogg_timestamps_(false) { |
| 97 DCHECK(demuxer_); | 98 DCHECK(demuxer_); |
| 98 | 99 |
| 99 bool is_encrypted = false; | 100 bool is_encrypted = false; |
| 101 int rotation = 0; | |
| 102 AVDictionaryEntry* rotation_entry = NULL; | |
| 100 | 103 |
| 101 // Determine our media format. | 104 // Determine our media format. |
| 102 switch (stream->codec->codec_type) { | 105 switch (stream->codec->codec_type) { |
| 103 case AVMEDIA_TYPE_AUDIO: | 106 case AVMEDIA_TYPE_AUDIO: |
| 104 type_ = AUDIO; | 107 type_ = AUDIO; |
| 105 AVStreamToAudioDecoderConfig(stream, &audio_config_, true); | 108 AVStreamToAudioDecoderConfig(stream, &audio_config_, true); |
| 106 is_encrypted = audio_config_.is_encrypted(); | 109 is_encrypted = audio_config_.is_encrypted(); |
| 107 break; | 110 break; |
| 108 case AVMEDIA_TYPE_VIDEO: | 111 case AVMEDIA_TYPE_VIDEO: |
| 109 type_ = VIDEO; | 112 type_ = VIDEO; |
| 110 AVStreamToVideoDecoderConfig(stream, &video_config_, true); | 113 AVStreamToVideoDecoderConfig(stream, &video_config_, true); |
| 111 is_encrypted = video_config_.is_encrypted(); | 114 is_encrypted = video_config_.is_encrypted(); |
| 115 | |
| 116 // Extract rotation metadata | |
| 117 rotation_entry = av_dict_get(stream->metadata, "rotate", NULL, 0); | |
| 118 if (rotation_entry && rotation_entry->value && rotation_entry->value[0]) | |
| 119 base::StringToInt(rotation_entry->value, &rotation); | |
| 120 | |
| 121 // Check that it is only a 90 degree increment | |
| 122 DCHECK(rotation == 0 || rotation == 90 || rotation == 180 || | |
|
scherkus (not reviewing)
2014/07/07 22:41:11
if you gracefully handle it below there's no need
| |
| 123 rotation == 270); | |
| 124 | |
| 125 // Translate to the appropriate enum | |
|
scherkus (not reviewing)
2014/07/07 22:41:11
comment isn't very helpful -- I'd remove it
| |
| 126 switch (rotation) { | |
| 127 case 90: | |
| 128 set_video_rotation(VIDEO_ROTATION_90); | |
| 129 break; | |
| 130 case 180: | |
| 131 set_video_rotation(VIDEO_ROTATION_180); | |
| 132 break; | |
| 133 case 270: | |
| 134 set_video_rotation(VIDEO_ROTATION_270); | |
| 135 break; | |
| 136 case 0: | |
| 137 set_video_rotation(VIDEO_ROTATION_0); | |
| 138 break; | |
| 139 default: | |
| 140 set_video_rotation(VIDEO_ROTATION_0); | |
| 141 LOG(ERROR) << "Unsupported video rotation metadata: " << rotation; | |
| 142 break; | |
| 143 } | |
| 144 | |
| 112 break; | 145 break; |
| 113 case AVMEDIA_TYPE_SUBTITLE: | 146 case AVMEDIA_TYPE_SUBTITLE: |
| 114 type_ = TEXT; | 147 type_ = TEXT; |
| 115 break; | 148 break; |
| 116 default: | 149 default: |
| 117 NOTREACHED(); | 150 NOTREACHED(); |
| 118 break; | 151 break; |
| 119 } | 152 } |
| 120 | 153 |
| 121 // Calculate the duration. | 154 // Calculate the duration. |
| (...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1167 } | 1200 } |
| 1168 for (size_t i = 0; i < buffered.size(); ++i) | 1201 for (size_t i = 0; i < buffered.size(); ++i) |
| 1169 host_->AddBufferedTimeRange(buffered.start(i), buffered.end(i)); | 1202 host_->AddBufferedTimeRange(buffered.start(i), buffered.end(i)); |
| 1170 } | 1203 } |
| 1171 | 1204 |
| 1172 void FFmpegDemuxer::OnDataSourceError() { | 1205 void FFmpegDemuxer::OnDataSourceError() { |
| 1173 host_->OnDemuxerError(PIPELINE_ERROR_READ); | 1206 host_->OnDemuxerError(PIPELINE_ERROR_READ); |
| 1174 } | 1207 } |
| 1175 | 1208 |
| 1176 } // namespace media | 1209 } // namespace media |
| OLD | NEW |