Browse code

Merge remote-tracking branch 'qatar/master'

* qatar/master:
drawtext: remove typo
pcm-mpeg: implement new audio decoding api
w32thread: port fixes to pthread_cond_broadcast() from x264.
doc: add editor configuration section with Vim and Emacs settings
dxva2.h: include d3d9.h to define LPDIRECT3DSURFACE9
avformat/utils: Drop unused goto label.
doxygen: Replace '\' by '@' in Doxygen markup tags.
cosmetics: drop some completely pointless parentheses
cljr: simplify CLJRContext
drawtext: introduce rand(min, max)
drawtext: introduce explicit draw/hide variable
rtmp: Use nb_invokes for all invoke commands

Conflicts:
libavcodec/mpegvideo.c
libavfilter/vf_drawtext.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2011/12/08 08:23:37
Showing 18 changed files
... ...
@@ -179,6 +179,31 @@ Casts should be used only when necessary. Unneeded parentheses
179 179
 should also be avoided if they don't make the code easier to understand.
180 180
 @end itemize
181 181
 
182
+@subsection Editor configuration
183
+In order to configure Vim to follow Libav formatting conventions, paste
184
+the following snippet into your @file{.vimrc}:
185
+@example
186
+" indentation rules for libav: 4 spaces, no tabs
187
+set expandtab
188
+set shiftwidth=4
189
+set softtabstop=4
190
+" allow tabs in Makefiles
191
+autocmd FileType make set noexpandtab shiftwidth=8 softtabstop=8
192
+" Trailing whitespace and tabs are forbidden, so highlight them.
193
+highlight ForbiddenWhitespace ctermbg=red guibg=red
194
+match ForbiddenWhitespace /\s\+$\|\t/
195
+" Do not highlight spaces at the end of line while typing on that line.
196
+autocmd InsertEnter * match ForbiddenWhitespace /\t\|\s\+\%#\@@<!$/
197
+@end example
198
+
199
+For Emacs, add these roughly equivalent lines to your @file{.emacs.d/init.el}:
200
+@example
201
+(setq c-default-style "k&r")
202
+(setq-default c-basic-offset 4)
203
+(setq-default indent-tabs-mode nil)
204
+(setq-default show-trailing-whitespace t)
205
+@end example
206
+
182 207
 @section Development Policy
183 208
 
184 209
 @enumerate
... ...
@@ -708,9 +708,10 @@ static int decodeChannelSoundUnit (ATRAC3Context *q, GetBitContext *gb, channel_
708 708
             memset(pSnd->IMDCT_buf, 0, 512 * sizeof(float));
709 709
 
710 710
         /* gain compensation and overlapping */
711
-        gainCompensateAndOverlap (pSnd->IMDCT_buf, &(pSnd->prevFrame[band*256]), &(pOut[band*256]),
712
-                                    &((pSnd->gainBlock[1 - (pSnd->gcBlkSwitch)]).gBlock[band]),
713
-                                    &((pSnd->gainBlock[pSnd->gcBlkSwitch]).gBlock[band]));
711
+        gainCompensateAndOverlap(pSnd->IMDCT_buf, &pSnd->prevFrame[band * 256],
712
+                                 &pOut[band * 256],
713
+                                 &pSnd->gainBlock[1 - pSnd->gcBlkSwitch].gBlock[band],
714
+                                 &pSnd->gainBlock[    pSnd->gcBlkSwitch].gBlock[band]);
714 715
     }
715 716
 
716 717
     /* Swap the gain control buffers for the next frame. */
... ...
@@ -795,7 +796,9 @@ static int decodeFrame(ATRAC3Context *q, const uint8_t* databuf,
795 795
         for (i=0 ; i<q->channels ; i++) {
796 796
 
797 797
             /* Set the bitstream reader at the start of a channel sound unit. */
798
-            init_get_bits(&q->gb, databuf+((i*q->bytes_per_frame)/q->channels), (q->bits_per_frame)/q->channels);
798
+            init_get_bits(&q->gb,
799
+                          databuf + i * q->bytes_per_frame / q->channels,
800
+                          q->bits_per_frame / q->channels);
799 801
 
800 802
             result = decodeChannelSoundUnit(q,&q->gb, &q->pUnits[i], out_samples[i], i, q->codingMode);
801 803
             if (result != 0)
... ...
@@ -35,9 +35,6 @@
35 35
 typedef struct CLJRContext{
36 36
     AVCodecContext *avctx;
37 37
     AVFrame picture;
38
-    int delta[16];
39
-    int offset[4];
40
-    GetBitContext gb;
41 38
 } CLJRContext;
42 39
 
43 40
 static int decode_frame(AVCodecContext *avctx,
... ...
@@ -47,6 +44,7 @@ static int decode_frame(AVCodecContext *avctx,
47 47
     const uint8_t *buf = avpkt->data;
48 48
     int buf_size = avpkt->size;
49 49
     CLJRContext * const a = avctx->priv_data;
50
+    GetBitContext gb;
50 51
     AVFrame *picture = data;
51 52
     AVFrame * const p= (AVFrame*)&a->picture;
52 53
     int x, y;
... ...
@@ -67,20 +65,20 @@ static int decode_frame(AVCodecContext *avctx,
67 67
     p->pict_type= AV_PICTURE_TYPE_I;
68 68
     p->key_frame= 1;
69 69
 
70
-    init_get_bits(&a->gb, buf, buf_size * 8);
70
+    init_get_bits(&gb, buf, buf_size * 8);
71 71
 
72 72
     for(y=0; y<avctx->height; y++){
73 73
         uint8_t *luma= &a->picture.data[0][ y*a->picture.linesize[0] ];
74 74
         uint8_t *cb= &a->picture.data[1][ y*a->picture.linesize[1] ];
75 75
         uint8_t *cr= &a->picture.data[2][ y*a->picture.linesize[2] ];
76 76
         for(x=0; x<avctx->width; x+=4){
77
-                luma[3] = get_bits(&a->gb, 5) << 3;
78
-            luma[2] = get_bits(&a->gb, 5) << 3;
79
-            luma[1] = get_bits(&a->gb, 5) << 3;
80
-            luma[0] = get_bits(&a->gb, 5) << 3;
77
+            luma[3] = get_bits(&gb, 5) << 3;
78
+            luma[2] = get_bits(&gb, 5) << 3;
79
+            luma[1] = get_bits(&gb, 5) << 3;
80
+            luma[0] = get_bits(&gb, 5) << 3;
81 81
             luma+= 4;
82
-            *(cb++) = get_bits(&a->gb, 6) << 2;
83
-            *(cr++) = get_bits(&a->gb, 6) << 2;
82
+            *(cb++) = get_bits(&gb, 6) << 2;
83
+            *(cr++) = get_bits(&gb, 6) << 2;
84 84
         }
85 85
     }
86 86
 
... ...
@@ -25,6 +25,7 @@
25 25
 
26 26
 #include <stdint.h>
27 27
 
28
+#include <d3d9.h>
28 29
 #include <dxva2api.h>
29 30
 
30 31
 #define FF_DXVA2_WORKAROUND_SCALING_LIST_ZIGZAG 1 ///< Work around for DXVA2 and old UVD/UVD+ ATI video cards
... ...
@@ -840,10 +840,14 @@ av_cold int MPV_common_init(MpegEncContext *s)
840 840
         FF_ALLOCZ_OR_GOTO(s->avctx, s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE, fail);
841 841
 
842 842
         s->parse_context.state = -1;
843
-        if ((s->avctx->debug & (FF_DEBUG_VIS_QP | FF_DEBUG_VIS_MB_TYPE)) || (s->avctx->debug_mv)) {
844
-            s->visualization_buffer[0] = av_malloc((s->mb_width * 16 + 2 * EDGE_WIDTH) * s->mb_height * 16 + 2 * EDGE_WIDTH);
845
-            s->visualization_buffer[1] = av_malloc((s->mb_width * 16 + 2 * EDGE_WIDTH) * s->mb_height * 16 + 2 * EDGE_WIDTH);
846
-            s->visualization_buffer[2] = av_malloc((s->mb_width * 16 + 2 * EDGE_WIDTH) * s->mb_height * 16 + 2 * EDGE_WIDTH);
843
+        if ((s->avctx->debug & (FF_DEBUG_VIS_QP | FF_DEBUG_VIS_MB_TYPE)) ||
844
+            s->avctx->debug_mv) {
845
+            s->visualization_buffer[0] = av_malloc((s->mb_width * 16 +
846
+                        2 * EDGE_WIDTH) * s->mb_height * 16 + 2 * EDGE_WIDTH);
847
+            s->visualization_buffer[1] = av_malloc((s->mb_width * 16 +
848
+                        2 * EDGE_WIDTH) * s->mb_height * 16 + 2 * EDGE_WIDTH);
849
+            s->visualization_buffer[2] = av_malloc((s->mb_width * 16 +
850
+                        2 * EDGE_WIDTH) * s->mb_height * 16 + 2 * EDGE_WIDTH);
847 851
         }
848 852
 
849 853
         s->context_initialized = 1;
... ...
@@ -1512,7 +1516,8 @@ void ff_print_debug_info(MpegEncContext *s, AVFrame *pict){
1512 1512
         }
1513 1513
     }
1514 1514
 
1515
-    if((s->avctx->debug&(FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) || (s->avctx->debug_mv)){
1515
+    if ((s->avctx->debug & (FF_DEBUG_VIS_QP | FF_DEBUG_VIS_MB_TYPE)) ||
1516
+        s->avctx->debug_mv) {
1516 1517
         const int shift= 1 + s->quarter_sample;
1517 1518
         int mb_y;
1518 1519
         uint8_t *ptr;
... ...
@@ -1538,7 +1543,7 @@ void ff_print_debug_info(MpegEncContext *s, AVFrame *pict){
1538 1538
             int mb_x;
1539 1539
             for(mb_x=0; mb_x<s->mb_width; mb_x++){
1540 1540
                 const int mb_index= mb_x + mb_y*s->mb_stride;
1541
-                if((s->avctx->debug_mv) && pict->motion_val){
1541
+                if (s->avctx->debug_mv && pict->motion_val) {
1542 1542
                   int type;
1543 1543
                   for(type=0; type<3; type++){
1544 1544
                     int direction = 0;
... ...
@@ -585,7 +585,7 @@ static inline void chroma_4mv_motion(MpegEncContext *s,
585 585
     if (src_y == (s->height >> 1))
586 586
         dxy &= ~2;
587 587
 
588
-    offset = (src_y * (s->uvlinesize)) + src_x;
588
+    offset = src_y * s->uvlinesize + src_x;
589 589
     ptr = ref_picture[1] + offset;
590 590
     if(s->flags&CODEC_FLAG_EMU_EDGE){
591 591
         if(   (unsigned)src_x > (s->h_edge_pos>>1) - (dxy &1) - 8
... ...
@@ -138,8 +138,8 @@ static int msrle_decode_8_16_24_32(AVCodecContext *avctx, AVPicture *pic, int de
138 138
     uint32_t av_uninit(pix32);
139 139
     unsigned int width= FFABS(pic->linesize[0]) / (depth >> 3);
140 140
 
141
-    output = pic->data[0] + (avctx->height - 1) * pic->linesize[0];
142
-    output_end = pic->data[0] + (avctx->height) * pic->linesize[0];
141
+    output     = pic->data[0] + (avctx->height - 1) * pic->linesize[0];
142
+    output_end = pic->data[0] +  avctx->height      * pic->linesize[0];
143 143
     while(src < data + srcsize) {
144 144
         p1 = *src++;
145 145
         if(p1 == 0) { //Escape code
... ...
@@ -121,17 +121,30 @@ static int pcm_bluray_parse_header(AVCodecContext *avctx,
121 121
     return 0;
122 122
 }
123 123
 
124
-static int pcm_bluray_decode_frame(AVCodecContext *avctx,
125
-                                   void *data,
126
-                                   int *data_size,
127
-                                   AVPacket *avpkt)
124
+typedef struct PCMBRDecode {
125
+    AVFrame frame;
126
+} PCMBRDecode;
127
+
128
+static av_cold int pcm_bluray_decode_init(AVCodecContext * avctx)
129
+{
130
+    PCMBRDecode *s = avctx->priv_data;
131
+
132
+    avcodec_get_frame_defaults(&s->frame);
133
+    avctx->coded_frame = &s->frame;
134
+
135
+    return 0;
136
+}
137
+
138
+static int pcm_bluray_decode_frame(AVCodecContext *avctx, void *data,
139
+                                   int *got_frame_ptr, AVPacket *avpkt)
128 140
 {
129 141
     const uint8_t *src = avpkt->data;
130 142
     int buf_size = avpkt->size;
143
+    PCMBRDecode *s = avctx->priv_data;
131 144
     int num_source_channels, channel, retval;
132
-    int sample_size, samples, output_size;
133
-    int16_t *dst16 = data;
134
-    int32_t *dst32 = data;
145
+    int sample_size, samples;
146
+    int16_t *dst16;
147
+    int32_t *dst32;
135 148
 
136 149
     if (buf_size < 4) {
137 150
         av_log(avctx, AV_LOG_ERROR, "PCM packet too small\n");
... ...
@@ -148,15 +161,14 @@ static int pcm_bluray_decode_frame(AVCodecContext *avctx,
148 148
     sample_size = (num_source_channels * avctx->bits_per_coded_sample) >> 3;
149 149
     samples = buf_size / sample_size;
150 150
 
151
-    output_size = samples * avctx->channels *
152
-                  (avctx->sample_fmt == AV_SAMPLE_FMT_S32 ? 4 : 2);
153
-    if (output_size > *data_size) {
154
-        av_log(avctx, AV_LOG_ERROR,
155
-               "Insufficient output buffer space (%d bytes, needed %d bytes)\n",
156
-               *data_size, output_size);
157
-        return -1;
151
+    /* get output buffer */
152
+    s->frame.nb_samples = samples;
153
+    if ((retval = avctx->get_buffer(avctx, &s->frame)) < 0) {
154
+        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
155
+        return retval;
158 156
     }
159
-    *data_size = output_size;
157
+    dst16 = (int16_t *)s->frame.data[0];
158
+    dst32 = (int32_t *)s->frame.data[0];
160 159
 
161 160
     if (samples) {
162 161
         switch (avctx->channel_layout) {
... ...
@@ -167,7 +179,7 @@ static int pcm_bluray_decode_frame(AVCodecContext *avctx,
167 167
             samples *= num_source_channels;
168 168
             if (AV_SAMPLE_FMT_S16 == avctx->sample_fmt) {
169 169
 #if HAVE_BIGENDIAN
170
-                memcpy(dst16, src, output_size);
170
+                memcpy(dst16, src, buf_size);
171 171
 #else
172 172
                 do {
173 173
                     *dst16++ = bytestream_get_be16(&src);
... ...
@@ -291,10 +303,13 @@ static int pcm_bluray_decode_frame(AVCodecContext *avctx,
291 291
         }
292 292
     }
293 293
 
294
+    *got_frame_ptr   = 1;
295
+    *(AVFrame *)data = s->frame;
296
+
294 297
     retval = src - avpkt->data;
295 298
     if (avctx->debug & FF_DEBUG_BITSTREAM)
296 299
         av_dlog(avctx, "pcm_bluray_decode_frame: decoded %d -> %d bytes\n",
297
-                retval, *data_size);
300
+                retval, buf_size);
298 301
     return retval;
299 302
 }
300 303
 
... ...
@@ -302,7 +317,10 @@ AVCodec ff_pcm_bluray_decoder = {
302 302
     .name           = "pcm_bluray",
303 303
     .type           = AVMEDIA_TYPE_AUDIO,
304 304
     .id             = CODEC_ID_PCM_BLURAY,
305
+    .priv_data_size = sizeof(PCMBRDecode),
306
+    .init           = pcm_bluray_decode_init,
305 307
     .decode         = pcm_bluray_decode_frame,
308
+    .capabilities   = CODEC_CAP_DR1,
306 309
     .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32,
307 310
                                          AV_SAMPLE_FMT_NONE},
308 311
     .long_name = NULL_IF_CONFIG_SMALL("PCM signed 16|20|24-bit big-endian for Blu-ray media"),
... ...
@@ -616,8 +616,8 @@ static inline void write16x4(uint8_t *dst, int dst_stride,
616 616
     *(dst_int+15*int_dst_stride) = *(src_int + 15);
617 617
 }
618 618
 
619
-/** \brief performs a 6x16 transpose of data in src, and stores it to dst
620
-    \todo FIXME: see if we can't spare some vec_lvsl() by them factorizing
619
+/** @brief performs a 6x16 transpose of data in src, and stores it to dst
620
+    @todo FIXME: see if we can't spare some vec_lvsl() by them factorizing
621 621
     out of unaligned_load() */
622 622
 #define readAndTranspose16x6(src, src_stride, r8, r9, r10, r11, r12, r13) {\
623 623
     register vec_u8 r0  = unaligned_load(0,             src);            \
... ...
@@ -94,7 +94,7 @@ do { \
94 94
 } while (0)
95 95
 
96 96
 
97
-/** \brief loads unaligned vector \a *src with offset \a offset
97
+/** @brief loads unaligned vector @a *src with offset @a offset
98 98
     and returns it */
99 99
 static inline vector unsigned char unaligned_load(int offset, uint8_t *src)
100 100
 {
... ...
@@ -58,7 +58,7 @@ void write_##type##_2d_array(const void *arg, int len, int len2)\
58 58
 /**
59 59
  * @name Predefined functions for printing tables
60 60
  *
61
- * \{
61
+ * @{
62 62
  */
63 63
 void write_int8_t_array     (const int8_t   *, int);
64 64
 void write_uint8_t_array    (const uint8_t  *, int);
... ...
@@ -69,7 +69,7 @@ void write_int8_t_2d_array  (const void *, int, int);
69 69
 void write_uint8_t_2d_array (const void *, int, int);
70 70
 void write_uint32_t_2d_array(const void *, int, int);
71 71
 void write_float_2d_array   (const void *, int, int);
72
-/** \} */ // end of printfuncs group
72
+/** @} */ // end of printfuncs group
73 73
 
74 74
 #define WRITE_ARRAY(prefix, type, name)                 \
75 75
     do {                                                \
... ...
@@ -236,7 +236,7 @@ static void vc1_put_signed_blocks_clamped(VC1Context *v)
236 236
         if (s->mb_x) {
237 237
             topleft_mb_pos = (s->mb_y - 1) * s->mb_stride + s->mb_x - 1;
238 238
             fieldtx        = v->fieldtx_plane[topleft_mb_pos];
239
-            stride_y       = (s->linesize) << fieldtx;
239
+            stride_y       = s->linesize << fieldtx;
240 240
             v_dist         = (16 - fieldtx) >> (fieldtx == 0);
241 241
             s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][0],
242 242
                                              s->dest[0] - 16 * s->linesize - 16,
... ...
@@ -115,9 +115,12 @@ static inline int pthread_mutex_unlock(pthread_mutex_t *m)
115 115
 /* for pre-Windows 6.0 platforms we need to define and use our own condition
116 116
  * variable and api */
117 117
 typedef struct {
118
+    pthread_mutex_t mtx_broadcast;
118 119
     pthread_mutex_t mtx_waiter_count;
119 120
     volatile int waiter_count;
120 121
     HANDLE semaphore;
122
+    HANDLE waiters_done;
123
+    int is_broadcast;
121 124
 } win32_cond_t;
122 125
 
123 126
 static void pthread_cond_init(pthread_cond_t *cond, const void *unused_attr)
... ...
@@ -136,8 +139,12 @@ static void pthread_cond_init(pthread_cond_t *cond, const void *unused_attr)
136 136
     win32_cond->semaphore = CreateSemaphore(NULL, 0, 0x7fffffff, NULL);
137 137
     if (!win32_cond->semaphore)
138 138
         return;
139
+    win32_cond->waiters_done = CreateEvent(NULL, FALSE, FALSE, NULL);
140
+    if (!win32_cond->waiters_done)
141
+        return;
139 142
 
140 143
     pthread_mutex_init(&win32_cond->mtx_waiter_count, NULL);
144
+    pthread_mutex_init(&win32_cond->mtx_broadcast, NULL);
141 145
 }
142 146
 
143 147
 static void pthread_cond_destroy(pthread_cond_t *cond)
... ...
@@ -149,7 +156,9 @@ static void pthread_cond_destroy(pthread_cond_t *cond)
149 149
 
150 150
     /* non native condition variables */
151 151
     CloseHandle(win32_cond->semaphore);
152
+    CloseHandle(win32_cond->waiters_done);
152 153
     pthread_mutex_destroy(&win32_cond->mtx_waiter_count);
154
+    pthread_mutex_destroy(&win32_cond->mtx_broadcast);
153 155
     av_freep(&win32_cond);
154 156
     cond->ptr = NULL;
155 157
 }
... ...
@@ -157,41 +166,70 @@ static void pthread_cond_destroy(pthread_cond_t *cond)
157 157
 static void pthread_cond_broadcast(pthread_cond_t *cond)
158 158
 {
159 159
     win32_cond_t *win32_cond = cond->ptr;
160
+    int have_waiter;
161
+
160 162
     if (cond_broadcast) {
161 163
         cond_broadcast(cond);
162 164
         return;
163 165
     }
164 166
 
165 167
     /* non native condition variables */
168
+    pthread_mutex_lock(&win32_cond->mtx_broadcast);
166 169
     pthread_mutex_lock(&win32_cond->mtx_waiter_count);
170
+    have_waiter = 0;
171
+
167 172
     if (win32_cond->waiter_count) {
168
-        ReleaseSemaphore(win32_cond->semaphore, win32_cond->waiter_count, NULL);
169
-        win32_cond->waiter_count = 0;
173
+        win32_cond->is_broadcast = 1;
174
+        have_waiter = 1;
170 175
     }
171
-    pthread_mutex_unlock(&win32_cond->mtx_waiter_count);
176
+
177
+    if (have_waiter) {
178
+        ReleaseSemaphore(win32_cond->semaphore, win32_cond->waiter_count, NULL);
179
+        pthread_mutex_unlock(&win32_cond->mtx_waiter_count);
180
+        WaitForSingleObject(win32_cond->waiters_done, INFINITE);
181
+        win32_cond->is_broadcast = 0;
182
+    } else
183
+        pthread_mutex_unlock(&win32_cond->mtx_waiter_count);
184
+    pthread_mutex_unlock(&win32_cond->mtx_broadcast);
172 185
 }
173 186
 
174 187
 static void pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
175 188
 {
176 189
     win32_cond_t *win32_cond = cond->ptr;
190
+    int last_waiter;
177 191
     if (cond_wait) {
178 192
         cond_wait(cond, mutex, INFINITE);
179 193
         return;
180 194
     }
181 195
 
182 196
     /* non native condition variables */
197
+    pthread_mutex_lock(&win32_cond->mtx_broadcast);
198
+    pthread_mutex_unlock(&win32_cond->mtx_broadcast);
199
+
183 200
     pthread_mutex_lock(&win32_cond->mtx_waiter_count);
184 201
     win32_cond->waiter_count++;
185 202
     pthread_mutex_unlock(&win32_cond->mtx_waiter_count);
186 203
 
204
+    // unlock the external mutex
187 205
     pthread_mutex_unlock(mutex);
188 206
     WaitForSingleObject(win32_cond->semaphore, INFINITE);
189
-    pthread_mutex_lock(mutex);
207
+
208
+    pthread_mutex_lock(&win32_cond->mtx_waiter_count);
209
+    win32_cond->waiter_count--;
210
+    last_waiter = !win32_cond->waiter_count && win32_cond->is_broadcast;
211
+    pthread_mutex_unlock(&win32_cond->mtx_waiter_count);
212
+
213
+    if (last_waiter)
214
+        SetEvent(win32_cond->waiters_done);
215
+
216
+    // lock the external mutex
217
+    return pthread_mutex_lock(mutex);
190 218
 }
191 219
 
192 220
 static void pthread_cond_signal(pthread_cond_t *cond)
193 221
 {
194 222
     win32_cond_t *win32_cond = cond->ptr;
223
+    int have_waiter;
195 224
     if (cond_signal) {
196 225
         cond_signal(cond);
197 226
         return;
... ...
@@ -199,11 +237,11 @@ static void pthread_cond_signal(pthread_cond_t *cond)
199 199
 
200 200
     /* non-native condition variables */
201 201
     pthread_mutex_lock(&win32_cond->mtx_waiter_count);
202
-    if (win32_cond->waiter_count) {
203
-        ReleaseSemaphore(win32_cond->semaphore, 1, NULL);
204
-        win32_cond->waiter_count--;
205
-    }
202
+    have_waiter = win32_cond->waiter_count;
206 203
     pthread_mutex_unlock(&win32_cond->mtx_waiter_count);
204
+
205
+    if (have_waiter)
206
+        ReleaseSemaphore(win32_cond->semaphore, 1, NULL);
207 207
 }
208 208
 
209 209
 static void w32thread_init(void)
... ...
@@ -335,8 +335,8 @@ static int dc1394_read_packet(AVFormatContext *c, AVPacket *pkt)
335 335
 
336 336
     res = dc1394_capture_dequeue(dc1394->camera, DC1394_CAPTURE_POLICY_WAIT, &dc1394->frame);
337 337
     if (res == DC1394_SUCCESS) {
338
-        dc1394->packet.data = (uint8_t *)(dc1394->frame->image);
339
-        dc1394->packet.pts = (dc1394->current_frame  * 1000000) / (dc1394->frame_rate);
338
+        dc1394->packet.data = (uint8_t *) dc1394->frame->image;
339
+        dc1394->packet.pts  = dc1394->current_frame * 1000000 / dc1394->frame_rate;
340 340
         res = dc1394->frame->image_bytes;
341 341
     } else {
342 342
         av_log(c, AV_LOG_ERROR, "DMA capture failed\n");
... ...
@@ -33,9 +33,11 @@
33 33
 #include "libavutil/file.h"
34 34
 #include "libavutil/eval.h"
35 35
 #include "libavutil/opt.h"
36
+#include "libavutil/random_seed.h"
36 37
 #include "libavutil/parseutils.h"
37 38
 #include "libavutil/pixdesc.h"
38 39
 #include "libavutil/tree.h"
40
+#include "libavutil/lfg.h"
39 41
 #include "avfilter.h"
40 42
 #include "drawutils.h"
41 43
 
... ...
@@ -67,6 +69,22 @@ static const char * const var_names[] = {
67 67
     NULL
68 68
 };
69 69
 
70
+static const char *fun2_names[] = {
71
+    "rand",
72
+};
73
+
74
+static double drand(void *opaque, double min, double max)
75
+{
76
+    return min + (max-min) / UINT_MAX * av_lfg_get(opaque);
77
+}
78
+
79
+typedef double (*eval_func2)(void *, double a, double b);
80
+
81
+static const eval_func2 fun2[] = {
82
+    drand,
83
+    NULL
84
+};
85
+
70 86
 enum var_name {
71 87
     VAR_MAIN_W, VAR_w, VAR_W,
72 88
     VAR_MAIN_H, VAR_h, VAR_H,
... ...
@@ -132,6 +150,10 @@ typedef struct {
132 132
     AVExpr *x_pexpr, *y_pexpr;      ///< parsed expressions for x and y
133 133
     int64_t basetime;               ///< base pts time in the real world for display
134 134
     double var_values[VAR_VARS_NB];
135
+    char   *d_expr;
136
+    AVExpr *d_pexpr;
137
+    int draw;                       ///< set to zero to prevent drawing
138
+    AVLFG  prng;                    ///< random
135 139
 } DrawTextContext;
136 140
 
137 141
 #define OFFSET(x) offsetof(DrawTextContext, x)
... ...
@@ -151,7 +173,7 @@ static const AVOption drawtext_options[]= {
151 151
 {"shadowy",  "set y",                OFFSET(shadowy),            AV_OPT_TYPE_INT,    {.dbl=0},     INT_MIN,  INT_MAX  },
152 152
 {"tabsize",  "set tab size",         OFFSET(tabsize),            AV_OPT_TYPE_INT,    {.dbl=4},     0,        INT_MAX  },
153 153
 {"basetime", "set base time",        OFFSET(basetime),           AV_OPT_TYPE_INT64,  {.dbl=AV_NOPTS_VALUE},     INT64_MIN,        INT64_MAX  },
154
-
154
+{"draw",     "if false do not draw", OFFSET(d_expr),             AV_OPT_TYPE_STRING, {.str="1"},   CHAR_MIN, CHAR_MAX },
155 155
 
156 156
 /* FT_LOAD_* flags */
157 157
 {"ft_load_flags", "set font loading flags for libfreetype",   OFFSET(ft_load_flags),  AV_OPT_TYPE_FLAGS,  {.dbl=FT_LOAD_DEFAULT|FT_LOAD_RENDER}, 0, INT_MAX, 0, "ft_load_flags" },
... ...
@@ -470,10 +492,15 @@ static int config_input(AVFilterLink *inlink)
470 470
         dtext->var_values[VAR_N] = 0;
471 471
     dtext->var_values[VAR_T]     = NAN;
472 472
 
473
+    av_lfg_init(&dtext->prng, av_get_random_seed());
474
+
473 475
     if ((ret = av_expr_parse(&dtext->x_pexpr, dtext->x_expr, var_names,
474
-                             NULL, NULL, NULL, NULL, 0, ctx)) < 0 ||
476
+                             NULL, NULL, fun2_names, fun2, 0, ctx)) < 0 ||
475 477
         (ret = av_expr_parse(&dtext->y_pexpr, dtext->y_expr, var_names,
476
-                             NULL, NULL, NULL, NULL, 0, ctx)) < 0)
478
+                             NULL, NULL, fun2_names, fun2, 0, ctx)) < 0 ||
479
+        (ret = av_expr_parse(&dtext->d_pexpr, dtext->d_expr, var_names,
480
+                             NULL, NULL, fun2_names, fun2, 0, ctx)) < 0)
481
+
477 482
         return AVERROR(EINVAL);
478 483
 
479 484
     return 0;
... ...
@@ -761,9 +788,13 @@ static int draw_text(AVFilterContext *ctx, AVFilterBufferRef *picref,
761 761
 
762 762
     dtext->var_values[VAR_LINE_H] = dtext->var_values[VAR_LH] = dtext->max_glyph_h;
763 763
 
764
-    dtext->x = dtext->var_values[VAR_X] = av_expr_eval(dtext->x_pexpr, dtext->var_values, NULL);
765
-    dtext->y = dtext->var_values[VAR_Y] = av_expr_eval(dtext->y_pexpr, dtext->var_values, NULL);
766
-    dtext->x = dtext->var_values[VAR_X] = av_expr_eval(dtext->x_pexpr, dtext->var_values, NULL);
764
+    dtext->x = dtext->var_values[VAR_X] = av_expr_eval(dtext->x_pexpr, dtext->var_values, &dtext->prng);
765
+    dtext->y = dtext->var_values[VAR_Y] = av_expr_eval(dtext->y_pexpr, dtext->var_values, &dtext->prng);
766
+    dtext->x = dtext->var_values[VAR_X] = av_expr_eval(dtext->x_pexpr, dtext->var_values, &dtext->prng);
767
+    dtext->draw = av_expr_eval(dtext->d_pexpr, dtext->var_values, &dtext->prng);
768
+
769
+    if(!dtext->draw)
770
+        return 0;
767 771
 
768 772
     dtext->x &= ~((1 << dtext->hsub) - 1);
769 773
     dtext->y &= ~((1 << dtext->vsub) - 1);
... ...
@@ -75,6 +75,7 @@ typedef struct RTMPContext {
75 75
     uint8_t       flv_header[11];             ///< partial incoming flv packet header
76 76
     int           flv_header_bytes;           ///< number of initialized bytes in flv_header
77 77
     int           nb_invokes;                 ///< keeps track of invoke messages
78
+    int           create_stream_invoke;       ///< invoke id for the create stream command
78 79
 } RTMPContext;
79 80
 
80 81
 #define PLAYER_KEY_OPEN_PART_LEN 30   ///< length of partial key used for first client digest signing
... ...
@@ -115,7 +116,7 @@ static void gen_connect(URLContext *s, RTMPContext *rt, const char *proto,
115 115
 
116 116
     ff_url_join(tcurl, sizeof(tcurl), proto, NULL, host, port, "/%s", rt->app);
117 117
     ff_amf_write_string(&p, "connect");
118
-    ff_amf_write_number(&p, 1.0);
118
+    ff_amf_write_number(&p, ++rt->nb_invokes);
119 119
     ff_amf_write_object_start(&p);
120 120
     ff_amf_write_field_name(&p, "app");
121 121
     ff_amf_write_string(&p, rt->app);
... ...
@@ -237,6 +238,7 @@ static void gen_create_stream(URLContext *s, RTMPContext *rt)
237 237
     ff_amf_write_string(&p, "createStream");
238 238
     ff_amf_write_number(&p, ++rt->nb_invokes);
239 239
     ff_amf_write_null(&p);
240
+    rt->create_stream_invoke = rt->nb_invokes;
240 241
 
241 242
     ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
242 243
     ff_rtmp_packet_destroy(&pkt);
... ...
@@ -257,7 +259,7 @@ static void gen_delete_stream(URLContext *s, RTMPContext *rt)
257 257
 
258 258
     p = pkt.data;
259 259
     ff_amf_write_string(&p, "deleteStream");
260
-    ff_amf_write_number(&p, 0.0);
260
+    ff_amf_write_number(&p, ++rt->nb_invokes);
261 261
     ff_amf_write_null(&p);
262 262
     ff_amf_write_number(&p, rt->main_channel_id);
263 263
 
... ...
@@ -281,7 +283,7 @@ static void gen_play(URLContext *s, RTMPContext *rt)
281 281
 
282 282
     p = pkt.data;
283 283
     ff_amf_write_string(&p, "play");
284
-    ff_amf_write_number(&p, 0.0);
284
+    ff_amf_write_number(&p, ++rt->nb_invokes);
285 285
     ff_amf_write_null(&p);
286 286
     ff_amf_write_string(&p, rt->playpath);
287 287
 
... ...
@@ -315,7 +317,7 @@ static void gen_publish(URLContext *s, RTMPContext *rt)
315 315
 
316 316
     p = pkt.data;
317 317
     ff_amf_write_string(&p, "publish");
318
-    ff_amf_write_number(&p, 0.0);
318
+    ff_amf_write_number(&p, ++rt->nb_invokes);
319 319
     ff_amf_write_null(&p);
320 320
     ff_amf_write_string(&p, rt->playpath);
321 321
     ff_amf_write_string(&p, "live");
... ...
@@ -614,7 +616,7 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt)
614 614
                  * releaseStream and FCPublish calls */
615 615
                 if (!pkt->data[10]) {
616 616
                     int pkt_id = (int) av_int2dbl(AV_RB64(pkt->data + 11));
617
-                    if (pkt_id == 4)
617
+                    if (pkt_id == rt->create_stream_invoke)
618 618
                         rt->state = STATE_CONNECTING;
619 619
                 }
620 620
                 if (rt->state != STATE_CONNECTING)
... ...
@@ -2247,7 +2247,6 @@ static int try_decode_frame(AVStream *st, AVPacket *avpkt, AVDictionary **option
2247 2247
             pkt.size -= ret;
2248 2248
         }
2249 2249
     }
2250
- fail:
2251 2250
     return ret;
2252 2251
 }
2253 2252
 
... ...
@@ -32,7 +32,7 @@
32 32
 #include <stdint.h>
33 33
 
34 34
 /** @name Error flags returned by av_lzo1x_decode
35
-  * \{ */
35
+  * @{ */
36 36
 /// end of the input buffer reached before decoding finished
37 37
 #define AV_LZO_INPUT_DEPLETED 1
38 38
 /// decoded data did not fit into output buffer
... ...
@@ -41,7 +41,7 @@
41 41
 #define AV_LZO_INVALID_BACKPTR 4
42 42
 /// a non-specific error in the compressed bitstream
43 43
 #define AV_LZO_ERROR 8
44
-/** \} */
44
+/** @} */
45 45
 
46 46
 #define AV_LZO_INPUT_PADDING 8
47 47
 #define AV_LZO_OUTPUT_PADDING 12