OSDN Git Service

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