OSDN Git Service

FFmpegExtractor: Don't use our extractor when we agree with StageFright
[android-x86/external-stagefright-plugins.git] / utils / ffmpeg_utils.h
1 /*
2  * Copyright 2012 Michael Chen <omxcodec@gmail.com>
3  * Copyright 2015 The CyanogenMod Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #ifndef FFMPEG_UTILS_H_
19
20 #define FFMPEG_UTILS_H_
21
22 #include <unistd.h>
23 #include <stdlib.h>
24
25 #include <utils/Condition.h>
26 #include <utils/Errors.h>
27 #include <utils/Mutex.h>
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 #include "config.h"
34 #include "libavformat/avformat.h"
35 #include "libavcodec/avcodec.h"
36
37 #include "libavutil/avstring.h"
38 #include "libavutil/colorspace.h"
39 #include "libavutil/mathematics.h"
40 #include "libavutil/pixdesc.h"
41 #include "libavutil/imgutils.h"
42 #include "libavutil/dict.h"
43 #include "libavutil/parseutils.h"
44 #include "libavutil/samplefmt.h"
45 #include "libavutil/avassert.h"
46 #include "libavformat/avformat.h"
47 #include "libavdevice/avdevice.h"
48 #include "libswscale/swscale.h"
49 #include "libavutil/opt.h"
50 #include "libavutil/internal.h"
51 #include "libavcodec/avfft.h"
52 #include "libavcodec/xiph.h"
53 #include "libswresample/swresample.h"
54
55 #include <system/audio.h>
56
57 #ifdef __cplusplus
58 }
59 #endif
60
61 //XXX hack!!!
62 #define SF_NOPTS_VALUE ((uint64_t)AV_NOPTS_VALUE-1)
63
64 namespace android {
65
66 //////////////////////////////////////////////////////////////////////////////////
67 // log
68 //////////////////////////////////////////////////////////////////////////////////
69 void nam_av_log_callback(void* ptr, int level, const char* fmt, va_list vl);
70 void nam_av_log_set_flags(int arg);
71
72 //////////////////////////////////////////////////////////////////////////////////
73 // constructor and destructor
74 //////////////////////////////////////////////////////////////////////////////////
75 status_t initFFmpeg();
76 void deInitFFmpeg();
77
78 //////////////////////////////////////////////////////////////////////////////////
79 // parser
80 //////////////////////////////////////////////////////////////////////////////////
81 int is_extradata_compatible_with_android(AVCodecContext *avctx);
82 int parser_split(AVCodecContext *avctx, const uint8_t *buf, int buf_size);
83
84 //////////////////////////////////////////////////////////////////////////////////
85 // packet queue
86 //////////////////////////////////////////////////////////////////////////////////
87
88 typedef struct PacketQueue {
89     AVPacket flush_pkt;
90     AVPacketList *first_pkt, *last_pkt;
91     int nb_packets;
92     int size;
93     int wait_for_data;
94     int abort_request;
95     Mutex lock;
96     Condition cond;
97 } PacketQueue;
98
99 void packet_queue_init(PacketQueue *q);
100 void packet_queue_destroy(PacketQueue *q);
101 void packet_queue_flush(PacketQueue *q);
102 void packet_queue_start(PacketQueue *q);
103 void packet_queue_abort(PacketQueue *q);
104 int packet_queue_is_wait_for_data(PacketQueue *q);
105 int packet_queue_put(PacketQueue *q, AVPacket *pkt);
106 int packet_queue_put_nullpacket(PacketQueue *q, int stream_index);
107 int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block);
108
109 //////////////////////////////////////////////////////////////////////////////////
110 // misc
111 //////////////////////////////////////////////////////////////////////////////////
112 bool setup_vorbis_extradata(uint8_t **extradata, int *extradata_size,
113         const uint8_t *header_start[3], const int header_len[3]);
114
115 int64_t get_timestamp(void);
116
117 audio_format_t to_android_audio_format(enum AVSampleFormat fmt);
118
119 }  // namespace android
120
121 #endif  // FFMPEG_UTILS_H_