summaryrefslogtreecommitdiff
path: root/src/libffmpeg/libavcodec/common.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/libffmpeg/libavcodec/common.h')
-rw-r--r--src/libffmpeg/libavcodec/common.h165
1 files changed, 145 insertions, 20 deletions
diff --git a/src/libffmpeg/libavcodec/common.h b/src/libffmpeg/libavcodec/common.h
index 5f51ba25d..a5c67d3a7 100644
--- a/src/libffmpeg/libavcodec/common.h
+++ b/src/libffmpeg/libavcodec/common.h
@@ -82,6 +82,12 @@ extern const struct AVOption avoptions_workaround_bug[11];
# define always_inline inline
#endif
+#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
+# define attribute_used __attribute__((used))
+#else
+# define attribute_used
+#endif
+
#ifndef EMULATE_INTTYPES
# include <inttypes.h>
#else
@@ -102,7 +108,7 @@ extern const struct AVOption avoptions_workaround_bug[11];
#endif /* HAVE_INTTYPES_H */
#ifndef INT64_MAX
-#define INT64_MAX 9223372036854775807LL
+#define INT64_MAX int64_t_C(9223372036854775807)
#endif
#ifdef EMULATE_FAST_INT
@@ -296,12 +302,56 @@ typedef struct PutBitContext {
#endif
} PutBitContext;
-void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size);
+static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
+{
+ s->buf = buffer;
+ s->buf_end = s->buf + buffer_size;
+#ifdef ALT_BITSTREAM_WRITER
+ s->index=0;
+ ((uint32_t*)(s->buf))[0]=0;
+// memset(buffer, 0, buffer_size);
+#else
+ s->buf_ptr = s->buf;
+ s->bit_left=32;
+ s->bit_buf=0;
+#endif
+}
+
+/* return the number of bits output */
+static inline int put_bits_count(PutBitContext *s)
+{
+#ifdef ALT_BITSTREAM_WRITER
+ return s->index;
+#else
+ return (s->buf_ptr - s->buf) * 8 + 32 - s->bit_left;
+#endif
+}
+
+static inline int put_bits_left(PutBitContext* s)
+{
+ return (s->buf_end - s->buf) * 8 - put_bits_count(s);
+}
+
+/* pad the end of the output stream with zeros */
+static inline void flush_put_bits(PutBitContext *s)
+{
+#ifdef ALT_BITSTREAM_WRITER
+ align_put_bits(s);
+#else
+ s->bit_buf<<= s->bit_left;
+ while (s->bit_left < 32) {
+ /* XXX: should test end of buffer */
+ *s->buf_ptr++=s->bit_buf >> 24;
+ s->bit_buf<<=8;
+ s->bit_left+=8;
+ }
+ s->bit_left=32;
+ s->bit_buf=0;
+#endif
+}
-int get_bit_count(PutBitContext *s); /* XXX: change function name */
void align_put_bits(PutBitContext *s);
-void flush_put_bits(PutBitContext *s);
-void put_string(PutBitContext * pbc, char *s);
+void put_string(PutBitContext * pbc, char *s, int put_zero);
/* bit input */
@@ -322,8 +372,6 @@ typedef struct GetBitContext {
int size_in_bits;
} GetBitContext;
-static inline int get_bits_count(GetBitContext *s);
-
#define VLC_TYPE int16_t
typedef struct VLC {
@@ -485,6 +533,28 @@ static inline uint8_t* pbBufPtr(PutBitContext *s)
#endif
}
+/**
+ *
+ * PutBitContext must be flushed & aligned to a byte boundary before calling this.
+ */
+static inline void skip_put_bytes(PutBitContext *s, int n){
+ assert((put_bits_count(s)&7)==0);
+#ifdef ALT_BITSTREAM_WRITER
+ FIXME may need some cleaning of the buffer
+ s->index += n<<3;
+#else
+ assert(s->bit_left==32);
+ s->buf_ptr += n;
+#endif
+}
+
+/**
+ * Changes the end of the buffer.
+ */
+static inline void set_put_bits_buffer_size(PutBitContext *s, int size){
+ s->buf_end= s->buf + size;
+}
+
/* Bitstream reader API docs:
name
abritary name which is used as prefix for the internal variables
@@ -807,8 +877,57 @@ static inline void skip_bits1(GetBitContext *s){
skip_bits(s, 1);
}
-void init_get_bits(GetBitContext *s,
- const uint8_t *buffer, int buffer_size);
+/**
+ * init GetBitContext.
+ * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits
+ * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end
+ * @param bit_size the size of the buffer in bits
+ */
+static inline void init_get_bits(GetBitContext *s,
+ const uint8_t *buffer, int bit_size)
+{
+ const int buffer_size= (bit_size+7)>>3;
+
+ s->buffer= buffer;
+ s->size_in_bits= bit_size;
+ s->buffer_end= buffer + buffer_size;
+#ifdef ALT_BITSTREAM_READER
+ s->index=0;
+#elif defined LIBMPEG2_BITSTREAM_READER
+#ifdef LIBMPEG2_BITSTREAM_READER_HACK
+ if ((int)buffer&1) {
+ /* word alignment */
+ s->cache = (*buffer++)<<24;
+ s->buffer_ptr = buffer;
+ s->bit_count = 16-8;
+ } else
+#endif
+ {
+ s->buffer_ptr = buffer;
+ s->bit_count = 16;
+ s->cache = 0;
+ }
+#elif defined A32_BITSTREAM_READER
+ s->buffer_ptr = (uint32_t*)buffer;
+ s->bit_count = 32;
+ s->cache0 = 0;
+ s->cache1 = 0;
+#endif
+ {
+ OPEN_READER(re, s)
+ UPDATE_CACHE(re, s)
+ UPDATE_CACHE(re, s)
+ CLOSE_READER(re, s)
+ }
+#ifdef A32_BITSTREAM_READER
+ s->cache1 = 0;
+#endif
+}
+
+static inline int get_bits_left(GetBitContext *s)
+{
+ return s->size_in_bits - get_bits_count(s);
+}
int check_marker(GetBitContext *s, const char *msg);
void align_get_bits(GetBitContext *s);
@@ -964,7 +1083,7 @@ static inline int get_xbits_trace(GetBitContext *s, int n, char *file, char *fun
#define tprintf printf
#else //TRACE
-#define tprintf(_arg...) {}
+#define tprintf(...) {}
#endif
/* define it to include statistics code (useful only for optimizing
@@ -1144,21 +1263,23 @@ static inline long long rdtsc()
}
#define START_TIMER \
-static uint64_t tsum=0;\
-static int tcount=0;\
-static int tskip_count=0;\
uint64_t tend;\
uint64_t tstart= rdtsc();\
#define STOP_TIMER(id) \
tend= rdtsc();\
-if(tcount<2 || tend - tstart < 4*tsum/tcount){\
- tsum+= tend - tstart;\
- tcount++;\
-}else\
- tskip_count++;\
-if(256*256*256*64%(tcount+tskip_count)==0){\
- fprintf(stderr, "%Ld dezicycles in %s, %d runs, %d skips\n", tsum*10/tcount, id, tcount, tskip_count);\
+{\
+ static uint64_t tsum=0;\
+ static int tcount=0;\
+ static int tskip_count=0;\
+ if(tcount<2 || tend - tstart < 8*tsum/tcount){\
+ tsum+= tend - tstart;\
+ tcount++;\
+ }else\
+ tskip_count++;\
+ if(256*256*256*64%(tcount+tskip_count)==0){\
+ av_log(NULL, AV_LOG_DEBUG, "%Ld dezicycles in %s, %d runs, %d skips\n", tsum*10/tcount, id, tcount, tskip_count);\
+ }\
}
#endif
@@ -1168,6 +1289,10 @@ if(256*256*256*64%(tcount+tskip_count)==0){\
#define malloc please_use_av_malloc
#define free please_use_av_free
#define realloc please_use_av_realloc
+#if !(defined(LIBAVFORMAT_BUILD) || defined(_FRAMEHOOK_H))
+#define printf please_use_av_log
+#define fprintf please_use_av_log
+#endif
#define CHECKED_ALLOCZ(p, size)\
{\