blob: 9be245ff1d418f1034c21ec33f3e57d1bdb431a3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_FFMPEG_FFMPEG_COMMON_H_
#define MEDIA_FFMPEG_FFMPEG_COMMON_H_
// Used for FFmpeg error codes.
#include <cerrno>
#include "base/compiler_specific.h"
#include "base/singleton.h"
// Used with URLProtocol.
typedef int64 offset_t;
// Include FFmpeg header files.
extern "C" {
// Temporarily disable possible loss of data warning.
// TODO(scherkus): fix and upstream the compiler warnings.
MSVC_PUSH_DISABLE_WARNING(4244);
#include "third_party/ffmpeg/include/libavcodec/avcodec.h"
#include "third_party/ffmpeg/include/libavformat/avformat.h"
#include "third_party/ffmpeg/include/libavutil/log.h"
MSVC_POP_WARNING();
} // extern "C"
namespace media {
// FFmpegLock is used to serialize calls to avcodec_open(), avcodec_close(),
// and av_find_stream_info() for an entire process because for whatever reason
// it does Very Bad Things to other FFmpeg instances.
//
// TODO(scherkus): track down and upstream a fix to FFmpeg, if possible.
class FFmpegLock : public Singleton<FFmpegLock> {
public:
Lock& lock();
private:
// Only allow Singleton to create and delete FFmpegLock.
friend struct DefaultSingletonTraits<FFmpegLock>;
FFmpegLock();
virtual ~FFmpegLock();
Lock lock_;
DISALLOW_COPY_AND_ASSIGN(FFmpegLock);
};
// Wraps FFmpeg's av_free() in a class that can be passed as a template argument
// to scoped_ptr_malloc.
class ScopedPtrAVFree {
public:
inline void operator()(void* x) const {
av_free(x);
}
};
// This assumes that the AVPacket being captured was allocated outside of
// FFmpeg via the new operator. Do not use this with AVPacket instances that
// are allocated via malloc() or av_malloc().
class ScopedPtrAVFreePacket {
public:
inline void operator()(void* x) const {
AVPacket* packet = static_cast<AVPacket*>(x);
av_free_packet(packet);
delete packet;
}
};
// FFmpeg MIME types.
namespace mime_type {
extern const char kFFmpegAudio[];
extern const char kFFmpegVideo[];
} // namespace mime_type
} // namespace media
#endif // MEDIA_FFMPEG_FFMPEG_COMMON_H_
|