| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef MEDIA_FFMPEG_FFMPEG_COMMON_H_ | 5 #ifndef MEDIA_FFMPEG_FFMPEG_COMMON_H_ |
| 6 #define MEDIA_FFMPEG_FFMPEG_COMMON_H_ | 6 #define MEDIA_FFMPEG_FFMPEG_COMMON_H_ |
| 7 | 7 |
| 8 // Used for FFmpeg error codes. | 8 // Used for FFmpeg error codes. |
| 9 #include <cerrno> | 9 #include <cerrno> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 13 #include "base/time.h" | 13 #include "base/time.h" |
| 14 #include "media/base/channel_layout.h" | 14 #include "media/base/channel_layout.h" |
| 15 #include "media/base/media_export.h" |
| 15 #include "media/video/video_decode_engine.h" | 16 #include "media/video/video_decode_engine.h" |
| 16 | 17 |
| 17 // Include FFmpeg header files. | 18 // Include FFmpeg header files. |
| 18 extern "C" { | 19 extern "C" { |
| 19 // Temporarily disable possible loss of data warning. | 20 // Temporarily disable possible loss of data warning. |
| 20 // TODO(scherkus): fix and upstream the compiler warnings. | 21 // TODO(scherkus): fix and upstream the compiler warnings. |
| 21 MSVC_PUSH_DISABLE_WARNING(4244); | 22 MSVC_PUSH_DISABLE_WARNING(4244); |
| 22 #include <libavcodec/avcodec.h> | 23 #include <libavcodec/avcodec.h> |
| 23 #include <libavformat/avformat.h> | 24 #include <libavformat/avformat.h> |
| 24 #include <libavformat/avio.h> | 25 #include <libavformat/avio.h> |
| (...skipping 22 matching lines...) Expand all Loading... |
| 47 AVPacket* packet = static_cast<AVPacket*>(x); | 48 AVPacket* packet = static_cast<AVPacket*>(x); |
| 48 av_free_packet(packet); | 49 av_free_packet(packet); |
| 49 delete packet; | 50 delete packet; |
| 50 } | 51 } |
| 51 }; | 52 }; |
| 52 | 53 |
| 53 // Converts an int64 timestamp in |time_base| units to a base::TimeDelta. | 54 // Converts an int64 timestamp in |time_base| units to a base::TimeDelta. |
| 54 // For example if |timestamp| equals 11025 and |time_base| equals {1, 44100} | 55 // For example if |timestamp| equals 11025 and |time_base| equals {1, 44100} |
| 55 // then the return value will be a base::TimeDelta for 0.25 seconds since that | 56 // then the return value will be a base::TimeDelta for 0.25 seconds since that |
| 56 // is how much time 11025/44100ths of a second represents. | 57 // is how much time 11025/44100ths of a second represents. |
| 57 base::TimeDelta ConvertFromTimeBase(const AVRational& time_base, | 58 MEDIA_EXPORT base::TimeDelta ConvertFromTimeBase(const AVRational& time_base, |
| 58 int64 timestamp); | 59 int64 timestamp); |
| 59 | 60 |
| 60 // Converts a base::TimeDelta into an int64 timestamp in |time_base| units. | 61 // Converts a base::TimeDelta into an int64 timestamp in |time_base| units. |
| 61 // For example if |timestamp| is 0.5 seconds and |time_base| is {1, 44100}, then | 62 // For example if |timestamp| is 0.5 seconds and |time_base| is {1, 44100}, then |
| 62 // the return value will be 22050 since that is how many 1/44100ths of a second | 63 // the return value will be 22050 since that is how many 1/44100ths of a second |
| 63 // represent 0.5 seconds. | 64 // represent 0.5 seconds. |
| 64 int64 ConvertToTimeBase(const AVRational& time_base, | 65 MEDIA_EXPORT int64 ConvertToTimeBase(const AVRational& time_base, |
| 65 const base::TimeDelta& timestamp); | 66 const base::TimeDelta& timestamp); |
| 66 | 67 |
| 67 VideoCodec CodecIDToVideoCodec(CodecID codec_id); | 68 VideoCodec CodecIDToVideoCodec(CodecID codec_id); |
| 68 CodecID VideoCodecToCodecID(VideoCodec video_codec); | 69 CodecID VideoCodecToCodecID(VideoCodec video_codec); |
| 69 | 70 |
| 70 // Converts FFmpeg's channel layout to chrome's ChannelLayout. |channels| can | 71 // Converts FFmpeg's channel layout to chrome's ChannelLayout. |channels| can |
| 71 // be used when FFmpeg's channel layout is not informative in order to make a | 72 // be used when FFmpeg's channel layout is not informative in order to make a |
| 72 // good guess about the plausible channel layout based on number of channels. | 73 // good guess about the plausible channel layout based on number of channels. |
| 73 ChannelLayout ChannelLayoutToChromeChannelLayout(int64_t layout, | 74 ChannelLayout ChannelLayoutToChromeChannelLayout(int64_t layout, |
| 74 int channels); | 75 int channels); |
| 75 | 76 |
| 76 // Calculates duration of one frame in the |stream| based on its frame rate. | 77 // Calculates duration of one frame in the |stream| based on its frame rate. |
| 77 base::TimeDelta GetFrameDuration(AVStream* stream); | 78 base::TimeDelta GetFrameDuration(AVStream* stream); |
| 78 | 79 |
| 79 // Get the timestamp of the next seek point after |timestamp|. | 80 // Get the timestamp of the next seek point after |timestamp|. |
| 80 // Returns true if a valid seek point was found after |timestamp| and | 81 // Returns true if a valid seek point was found after |timestamp| and |
| 81 // |seek_time| was set. Returns false if a seek point could not be | 82 // |seek_time| was set. Returns false if a seek point could not be |
| 82 // found or the parameters are invalid. | 83 // found or the parameters are invalid. |
| 83 bool GetSeekTimeAfter(AVStream* stream, | 84 MEDIA_EXPORT bool GetSeekTimeAfter(AVStream* stream, |
| 84 const base::TimeDelta& timestamp, | 85 const base::TimeDelta& timestamp, |
| 85 base::TimeDelta* seek_time); | 86 base::TimeDelta* seek_time); |
| 86 | 87 |
| 87 // Get the number of bytes required to play the stream over a specified | 88 // Get the number of bytes required to play the stream over a specified |
| 88 // time range. This is an estimate based on the available index data. | 89 // time range. This is an estimate based on the available index data. |
| 89 // Returns true if input time range was valid and |bytes|, |range_start|, | 90 // Returns true if input time range was valid and |bytes|, |range_start|, |
| 90 // and |range_end|, were set. Returns false if the range was invalid or we don't | 91 // and |range_end|, were set. Returns false if the range was invalid or we don't |
| 91 // have enough index data to make an estimate. | 92 // have enough index data to make an estimate. |
| 92 // | 93 // |
| 93 // |bytes| - The number of bytes in the stream for the specified range. | 94 // |bytes| - The number of bytes in the stream for the specified range. |
| 94 // |range_start| - The start time for the range covered by |bytes|. This | 95 // |range_start| - The start time for the range covered by |bytes|. This |
| 95 // may be different than |start_time| if the index doesn't | 96 // may be different than |start_time| if the index doesn't |
| 96 // have data for that exact time. |range_start| <= |start_time| | 97 // have data for that exact time. |range_start| <= |start_time| |
| 97 // |range_end| - The end time for the range covered by |bytes|. This may be | 98 // |range_end| - The end time for the range covered by |bytes|. This may be |
| 98 // different than |end_time| if the index doesn't have data for | 99 // different than |end_time| if the index doesn't have data for |
| 99 // that exact time. |range_end| >= |end_time| | 100 // that exact time. |range_end| >= |end_time| |
| 100 bool GetStreamByteCountOverRange(AVStream* stream, | 101 MEDIA_EXPORT bool GetStreamByteCountOverRange(AVStream* stream, |
| 101 const base::TimeDelta& start_time, | 102 const base::TimeDelta& start_time, |
| 102 const base::TimeDelta& end_time, | 103 const base::TimeDelta& end_time, |
| 103 int64* bytes, | 104 int64* bytes, |
| 104 base::TimeDelta* range_start, | 105 base::TimeDelta* range_start, |
| 105 base::TimeDelta* range_end); | 106 base::TimeDelta* range_end); |
| 106 | 107 |
| 107 // Calculates the width and height of the video surface using the video's | 108 // Calculates the width and height of the video surface using the video's |
| 108 // encoded dimensions and sample_aspect_ratio. | 109 // encoded dimensions and sample_aspect_ratio. |
| 109 int GetSurfaceHeight(AVStream* stream); | 110 int GetSurfaceHeight(AVStream* stream); |
| 110 int GetSurfaceWidth(AVStream* stream); | 111 int GetSurfaceWidth(AVStream* stream); |
| 111 | 112 |
| 112 // Closes & destroys all AVStreams in the context and then closes & | 113 // Closes & destroys all AVStreams in the context and then closes & |
| 113 // destroys the AVFormatContext. | 114 // destroys the AVFormatContext. |
| 114 void DestroyAVFormatContext(AVFormatContext* format_context); | 115 void DestroyAVFormatContext(AVFormatContext* format_context); |
| 115 | 116 |
| 116 } // namespace media | 117 } // namespace media |
| 117 | 118 |
| 118 #endif // MEDIA_FFMPEG_FFMPEG_COMMON_H_ | 119 #endif // MEDIA_FFMPEG_FFMPEG_COMMON_H_ |
| OLD | NEW |