-
Notifications
You must be signed in to change notification settings - Fork 2
/
omx_bak.c
732 lines (618 loc) · 19.5 KB
/
omx_bak.c
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
/**
*
* ToxBlinkenwall
* (C)Zoff <[email protected]> in 2017 - 2019
*
* https://github.com/zoff99/ToxBlinkenwall
*
*/
/**
* @file omx.c Raspberry Pi VideoCoreIV OpenMAX interface
*
* Copyright (C) 2016 - 2017 Creytiv.com
* Copyright (C) 2016 - 2017 Jonathan Sieber
* Copyright (C) 2018 - 2019 Zoff <[email protected]>
*/
#include "omx.h"
/*
* forward func declarations (acutal functions in toxblinkenwall.c)
*/
void dbg(int level, const char *fmt, ...);
void usleep_usec2(uint64_t usec)
{
struct timespec ts;
ts.tv_sec = usec / 1000000;
ts.tv_nsec = (usec % 1000000) * 1000;
nanosleep(&ts, NULL);
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Avoids a VideoCore header warning about clock_gettime() */
#include <time.h>
#include <sys/time.h>
#include <bcm_host.h>
/**
* @defgroup omx omx
*
* TODO:
* * Proper sync OMX events across threads, instead of busy waiting
*/
static const int VIDEO_RENDER_PORT = 90;
static void *global_st_buffers = 0;
static OMX_ERRORTYPE EventHandler(OMX_HANDLETYPE hComponent, OMX_PTR pAppData,
OMX_EVENTTYPE eEvent, OMX_U32 nData1, OMX_U32 nData2,
OMX_PTR pEventData)
{
(void) hComponent;
switch (eEvent)
{
case OMX_EventCmdComplete:
if (nData1 == OMX_CommandFlush)
{
printf("omx.EventHandler: OMX_CommandFlush command completed\n"
"d1=%x\td2=%x\teventData=%p\tappdata=%p\n",
nData1, nData2, pEventData, pAppData);
}
else if (nData1 == OMX_CommandStateSet)
{
printf("omx.EventHandler: OMX_CommandStateSet command completed\n"
"d1=%x\td2=%x\teventData=%p\tappdata=%p\n",
nData1, nData2, pEventData, pAppData);
}
else if (nData1 == OMX_CommandPortEnable)
{
printf("omx.EventHandler: OMX_CommandPortEnable command completed\n"
"d1=%x\td2=%x\teventData=%p\tappdata=%p\n",
nData1, nData2, pEventData, pAppData);
}
else if (nData1 == OMX_CommandPortDisable)
{
printf("omx.EventHandler: OMX_CommandPortDisable command completed\n"
"d1=%x\td2=%x\teventData=%p\tappdata=%p\n",
nData1, nData2, pEventData, pAppData);
}
else
{
printf("omx.EventHandler: Previous command completed\n"
"d1=%x\td2=%x\teventData=%p\tappdata=%p\n",
nData1, nData2, pEventData, pAppData);
}
break;
case OMX_EventParamOrConfigChanged:
printf("omx.EventHandler: Param_or_config changed event type "
"hComponent:0x%08x\tdata1=%x\tdata2=%x\n",
hComponent, nData1, nData2);
break;
case OMX_EventError:
if (nData1 == OMX_CommandStateSet)
{
printf("omx.EventHandler: OMX_EventError: OMX_CommandStateSet\n");
}
else if (nData1 == OMX_CommandPortEnable)
{
printf("omx.EventHandler: OMX_EventError: OMX_CommandPortEnable\n");
}
printf("omx.EventHandler: Error event type "
"hComponent:0x%08x\tdata1=%x\tdata2=%x\n",
hComponent, nData1, nData2);
break;
case OMX_EventPortSettingsChanged:
printf("omx.EventHandler: EventPortSettingsChanged event type "
"data1=%x\tdata2=%x\n", nData1, nData2);
break;
default:
printf("omx.EventHandler: Unknown event type %d\t"
"data1=%x data2=%x\n", eEvent, nData1, nData2);
return -1;
break;
}
return 0;
}
static OMX_ERRORTYPE EmptyBufferDone(OMX_HANDLETYPE hComponent,
OMX_PTR pAppData,
OMX_BUFFERHEADERTYPE *pBuffer)
{
(void) hComponent;
(void) pAppData;
(void) pBuffer;
/* TODO: Wrap every call that can generate an event,
* and panic if an unexpected event arrives */
// printf("omx.EmptyBufferDone:called:ptr=%p pnum=%d\n", (void *)pBuffer, (int)((void *)pBuffer - (void *)global_st_buffers));
return 0;
}
static OMX_ERRORTYPE FillBufferDone(OMX_HANDLETYPE hComponent,
OMX_PTR pAppData, OMX_BUFFERHEADERTYPE *pBuffer)
{
(void) hComponent;
(void) pAppData;
(void) pBuffer;
// printf("FillBufferDone\n");
return 0;
}
static struct OMX_CALLBACKTYPE callbacks =
{
EventHandler,
EmptyBufferDone,
&FillBufferDone
};
static void free_omx_buffers(struct omx_state *st)
{
if (!st)
{
return;
}
if (!st->video_render)
{
return;
}
OMX_ERRORTYPE err;
// free OMX buffers
if (st->buffers)
{
for (int i = 0; i < st->num_buffers; i++)
{
printf("OMX_FreeBuffer: %d\n", i);
err = OMX_FreeBuffer(st->video_render, VIDEO_RENDER_PORT, st->buffers[i]);
if (err != OMX_ErrorNone)
{
printf("OMX_FreeBuffer failed: %d\n", err);
}
else
{
printf("OMX_FreeBuffer OK: %d\n", err);
usleep_usec2(1000);
}
}
usleep_usec2(1000);
printf("OMX_FreeBuffer *DONE*\n");
free(st->buffers);
st->buffers = NULL;
st->num_buffers = 0;
st->current_buffer = 0;
}
global_st_buffers = 0;
}
static void block_until_flushed(void)
{
// TODO: write me: wait until buffers are actually flushed
usleep_usec2(25000);
}
int omx_init(struct omx_state *st)
{
OMX_ERRORTYPE err;
bcm_host_init();
if (!st)
{
return ENOENT;
}
st->buffers=NULL;
err = OMX_Init();
err |= OMX_GetHandle(&st->video_render, "OMX.broadcom.video_render", 0, &callbacks);
if (!st->video_render || err != 0)
{
printf("omx: Failed to create OMX video_render component\n");
return ENOENT;
}
else
{
printf("omx: created video_render component\n");
return 0;
}
}
/* Some busy loops to verify we're running in order */
static void block_until_state_changed(OMX_HANDLETYPE hComponent, OMX_STATETYPE wanted_eState)
{
OMX_STATETYPE eState;
unsigned int i = 0;
uint32_t loop_counter = 0;
while (i++ == 0 || eState != wanted_eState)
{
OMX_GetState(hComponent, &eState);
if (eState != wanted_eState)
{
usleep_usec2(1000);
}
loop_counter++;
if (loop_counter > 200)
{
printf("OMX: block_until_state_changed: TIMEOUT\n");
// we don't want to get stuck here
break;
}
}
}
void omx_deinit(struct omx_state *st)
{
if (!st)
{
return;
}
if (!st->video_render)
{
return;
}
printf("omx_deinit:005\n");
OMX_FreeHandle(st->video_render);
usleep_usec2(20000);
printf("omx_deinit:006\n");
OMX_Deinit();
printf("omx_deinit:099\n");
}
static void block_until_port_changed(OMX_HANDLETYPE hComponent,
OMX_U32 nPortIndex, OMX_BOOL bEnabled)
{
OMX_ERRORTYPE r;
OMX_PARAM_PORTDEFINITIONTYPE portdef;
OMX_U32 i = 0;
memset(&portdef, 0, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
portdef.nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
portdef.nVersion.nVersion = OMX_VERSION;
portdef.nPortIndex = nPortIndex;
uint32_t loop_counter = 0;
while (i++ == 0 || portdef.bEnabled != bEnabled)
{
r = OMX_GetParameter(hComponent,
OMX_IndexParamPortDefinition, &portdef);
if (r != OMX_ErrorNone)
{
printf("OMX: block_until_port_changed: OMX_GetParameter "
" failed with Result=%d\n", r);
}
if (portdef.bEnabled != bEnabled)
{
usleep_usec2(1000);
}
loop_counter++;
if (loop_counter > 200)
{
printf("OMX: block_until_port_changed: TIMEOUT\n");
// we don't want to get stuck here
break;
}
}
}
void omx_display_disable(struct omx_state *st)
{
printf("omx_display_disable\n");
OMX_ERRORTYPE err;
OMX_CONFIG_DISPLAYREGIONTYPE config;
if (!st)
{
return;
}
if (!st->video_render)
{
return;
}
printf("OMX flush buffers\n");
if ((err = OMX_SendCommand(st->video_render, OMX_CommandFlush, VIDEO_RENDER_PORT, NULL)) != OMX_ErrorNone)
{
printf("OMX Failed to flush buffers: %d\n", (int)err);
}
block_until_flushed();
//
//
//
//
//
//
printf("OMX switch state of the encoder component to idle\n");
if ((err = OMX_SendCommand(st->video_render, OMX_CommandStateSet, OMX_StateIdle, NULL)) != OMX_ErrorNone)
{
printf("OMX: Failed to switch state of the encoder component to idle: %d\n", (int)err);
}
block_until_state_changed(st->video_render, OMX_StateIdle);
//
//
//
//
//
//
// Disable the port
printf("OMX disable port\n");
if ((err = OMX_SendCommand(st->video_render, OMX_CommandPortDisable, VIDEO_RENDER_PORT, NULL)) != OMX_ErrorNone)
{
printf("OMX Failed to disable port: %d\n", (int)err);
}
//
//
//
printf("OMX free buffers\n");
free_omx_buffers(st);
//
//
//
//
//
//
block_until_port_changed(st->video_render, VIDEO_RENDER_PORT, OMX_FALSE);
//
//
//
printf("OMX switch state of the encoder component to loaded\n");
if ((err = OMX_SendCommand(st->video_render, OMX_CommandStateSet, OMX_StateLoaded, NULL)) != OMX_ErrorNone)
{
printf("OMX: Failed to switch state of the encoder component to loaded: %d\n", (int)err);
}
block_until_state_changed(st->video_render, OMX_StateLoaded);
}
#ifdef DEBUG_OMX_TEST_PROGRAM
int omx_display_xy(int flag, struct omx_state *st,
int width, int height, int stride)
{
unsigned int i;
OMX_PARAM_PORTDEFINITIONTYPE portdef;
OMX_CONFIG_DISPLAYREGIONTYPE config;
OMX_ERRORTYPE err = 0;
printf("omx_update_size %d %d %d\n", width, height, stride);
memset(&config, 0, sizeof(OMX_CONFIG_DISPLAYREGIONTYPE));
config.nSize = sizeof(OMX_CONFIG_DISPLAYREGIONTYPE);
config.nVersion.nVersion = OMX_VERSION;
config.nPortIndex = VIDEO_RENDER_PORT;
//
//
//
//
config.dest_rect.x_offset = 0;
config.dest_rect.y_offset = 0;
config.dest_rect.width = (int)(1920 / 2);
config.dest_rect.height = (int)(1080 / 2);
config.mode = OMX_DISPLAY_MODE_LETTERBOX;
if (flag == 0)
{
config.transform = OMX_DISPLAY_ROT0;
}
else
{
config.transform = OMX_DISPLAY_ROT90;
}
config.fullscreen = OMX_FALSE;
config.set = (OMX_DISPLAYSETTYPE)(OMX_DISPLAY_SET_TRANSFORM | OMX_DISPLAY_SET_DEST_RECT |
OMX_DISPLAY_SET_FULLSCREEN | OMX_DISPLAY_SET_MODE);
//
printf("OMX_SetParameter\n");
err = OMX_SetParameter(st->video_render,
OMX_IndexConfigDisplayRegion, &config);
return err;
}
#endif
int omx_change_video_out_rotation(struct omx_state *st, int angle)
{
if (!st)
{
return 1;
}
if (!st->video_render)
{
return 1;
}
unsigned int i;
OMX_PARAM_PORTDEFINITIONTYPE portdef;
OMX_CONFIG_DISPLAYREGIONTYPE config;
OMX_ERRORTYPE err = 0;
memset(&config, 0, sizeof(OMX_CONFIG_DISPLAYREGIONTYPE));
config.nSize = sizeof(OMX_CONFIG_DISPLAYREGIONTYPE);
config.nVersion.nVersion = OMX_VERSION;
config.nPortIndex = VIDEO_RENDER_PORT;
if (angle == 90)
{
config.transform = OMX_DISPLAY_ROT90;
}
else if (angle == 180)
{
config.transform = OMX_DISPLAY_ROT180;
}
else if (angle == 270)
{
config.transform = OMX_DISPLAY_ROT270;
}
else
{
// for any other angle value just assume "0" degrees
config.transform = OMX_DISPLAY_ROT0;
}
//
config.set = (OMX_DISPLAYSETTYPE)(OMX_DISPLAY_SET_TRANSFORM);
//
printf("OMX_SetParameter(2)\n");
err |= OMX_SetParameter(st->video_render,
OMX_IndexConfigDisplayRegion, &config);
return err;
}
int omx_display_enable(struct omx_state *st, int width, int height, int stride)
{
unsigned int i;
OMX_PARAM_PORTDEFINITIONTYPE portdef;
OMX_CONFIG_DISPLAYREGIONTYPE config;
OMX_ERRORTYPE err = 0;
//
printf("OMX command state set IDLE\n");
if ((err = OMX_SendCommand(st->video_render, OMX_CommandStateSet, OMX_StateIdle, NULL)) != OMX_ErrorNone)
{
printf("OMX Failed to set IDLE state: %d\n", (int)err);
}
//
printf("omx_update_size %d %d %d\n", width, height, stride);
memset(&config, 0, sizeof(OMX_CONFIG_DISPLAYREGIONTYPE));
config.nSize = sizeof(OMX_CONFIG_DISPLAYREGIONTYPE);
config.nVersion.nVersion = OMX_VERSION;
config.nPortIndex = VIDEO_RENDER_PORT;
//
config.fullscreen = OMX_TRUE;
config.mode = OMX_DISPLAY_MODE_LETTERBOX;
config.set = (OMX_DISPLAYSETTYPE)(OMX_DISPLAY_SET_FULLSCREEN | OMX_DISPLAY_SET_MODE);
//
printf("OMX_SetParameter(3)\n");
err = OMX_SetParameter(st->video_render, OMX_IndexConfigDisplayRegion, &config);
if (err != 0)
{
printf("omx_display_enable: couldn't configure display region: %d\n", (int)err);
}
memset(&portdef, 0, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
portdef.nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
portdef.nVersion.nVersion = OMX_VERSION;
portdef.nPortIndex = VIDEO_RENDER_PORT;
/* specify buffer requirements */
printf("OMX_GetParameter\n");
err = OMX_GetParameter(st->video_render, OMX_IndexParamPortDefinition, &portdef);
if (err != 0)
{
printf("omx_display_enable: couldn't retrieve port def: %d\n", (int)err);
err = ENOMEM;
goto exit;
}
//
printf("omx port definition(before): h=%d w=%d s=%d sh=%d enable=%d\n",
portdef.format.video.nFrameWidth,
portdef.format.video.nFrameHeight,
portdef.format.video.nStride,
portdef.format.video.nSliceHeight,
portdef.bEnabled);
//
portdef.format.video.nFrameWidth = width;
portdef.format.video.nFrameHeight = height;
portdef.format.video.nStride = stride;
portdef.format.video.nSliceHeight = height;
//
portdef.bEnabled = 1;
//
printf("omx port definition(after): h=%d w=%d s=%d sh=%d enable=%d\n",
portdef.format.video.nFrameWidth,
portdef.format.video.nFrameHeight,
portdef.format.video.nStride,
portdef.format.video.nSliceHeight,
portdef.bEnabled);
//
int want_buffers = 4;
portdef.nBufferCountActual = want_buffers;
if ((int)portdef.nBufferCountActual < (int)portdef.nBufferCountMin)
{
portdef.nBufferCountActual = portdef.nBufferCountMin;
want_buffers = portdef.nBufferCountMin;
}
printf("OMX_SetParameter(4)\n");
err = OMX_SetParameter(st->video_render, OMX_IndexParamPortDefinition, &portdef);
if (err)
{
printf("omx_display_enable: could not set port definition: %d\n", (int)err);
err = EINVAL;
goto exit;
}
printf("OMX_GetParameter(2)\n");
err = OMX_GetParameter(st->video_render, OMX_IndexParamPortDefinition, &portdef);
if (portdef.format.video.nFrameWidth != width || portdef.format.video.nFrameHeight != height || portdef.format.video.nStride != stride)
{
printf("OMX: could not set requested resolution: %d\n", (int)err);
err = EINVAL;
goto exit;
}
if(portdef.bEnabled != 1){//如果端口关闭就打开 by aphero
err |=OMX_SendCommand(st->video_render,OMX_CommandPortEnable, VIDEO_RENDER_PORT, NULL);//前面关闭了,一定要打开,aphero
}
if (!st->buffers)
{
printf("OMX_Buffer_counts:nBufferCountActual=%d want_buffers=%d nBufferCountMin=%d\n",
(int)portdef.nBufferCountActual,
(int)want_buffers,
(int)portdef.nBufferCountMin);
st->buffers = calloc(1, want_buffers * sizeof(void *));
global_st_buffers = (void *)st->buffers;
st->num_buffers = want_buffers;
st->current_buffer = 0;
for (i = 0; i < want_buffers; i++)
{
printf("OMX_AllocateBuffer\n");
err = OMX_AllocateBuffer(st->video_render, &st->buffers[i], VIDEO_RENDER_PORT, st, portdef.nBufferSize);
if (err)
{
printf("OMX_AllocateBuffer failed: %d\n", (int)err);
err = ENOMEM;
goto exit;
}
}
}
//
//
//
block_until_state_changed(st->video_render, OMX_StateIdle);
//
//
//
printf("OMX: ===================\n");
printf("OMX: ===================\n");
printf("OMX: ===================\n");
printf("OMX: command port enable VIDEO RENDER PORT\n");
if ((err = OMX_SendCommand(st->video_render, OMX_CommandPortEnable, VIDEO_RENDER_PORT, NULL)) != OMX_ErrorNone)
{
printf("OMX Failed to enable port: %d\n", (int)err);
}
block_until_port_changed(st->video_render, VIDEO_RENDER_PORT, OMX_TRUE);
usleep_usec2(10000);
printf("OMX: ===================\n");
printf("OMX: ===================\n");
printf("OMX: ===================\n");
printf("OMX: omx_update_size: send to execute state\n");
OMX_SendCommand(st->video_render, OMX_CommandStateSet,
OMX_StateExecuting, NULL);
if (err)
{
printf("omx_update_size: send to execute state ERROR: %d\n", (int)err);
}
block_until_state_changed(st->video_render, OMX_StateExecuting);
exit:
return err;
}
int omx_display_input_buffer(struct omx_state *st,
void **pbuf, uint32_t *plen)
{
int buf_idx;
if (!st)
{
return EINVAL;
}
if (!st->buffers)
{
return EINVAL;
}
st->current_buffer = (st->current_buffer + 1) % st->num_buffers;
buf_idx = st->current_buffer;
*pbuf = st->buffers[buf_idx]->pBuffer;
*plen = st->buffers[buf_idx]->nAllocLen;
st->buffers[buf_idx]->nFilledLen = *plen;
st->buffers[buf_idx]->nOffset = 0;
// printf("omx_get_display_input_buffer:idx=%d ptr=%p pnum=%d\n", buf_idx, (void *)st->buffers[buf_idx], (int)((void *)st->buffers[buf_idx] - (void *)st->buffers));
return 0;
}
static OMX_TICKS to_omx_ticks(int64_t value)
{
OMX_TICKS s;
s.nLowPart = value & 0xffffffff;
s.nHighPart = value >> 32;
return s;
}
int omx_display_flush_buffer(struct omx_state *st, uint32_t data_len, uint32_t ms_offset)
{
if (!st)
{
return 1;
}
if (!st->video_render)
{
return 1;
}
int buf_idx = st->current_buffer;
st->buffers[buf_idx]->nFlags = OMX_BUFFERFLAG_STARTTIME; // OMX_BUFFERFLAG_ENDOFFRAME; // OMX_BUFFERFLAG_STARTTIME;
st->buffers[buf_idx]->nOffset = 0;
st->buffers[buf_idx]->nFilledLen = data_len;
st->buffers[buf_idx]->nTimeStamp = omx_ticks_from_s64(0); // to_omx_ticks(ms_offset * 1000); // omx_ticks_from_s64(ms_offset);
if (OMX_EmptyThisBuffer(st->video_render, st->buffers[buf_idx]) != OMX_ErrorNone)
{
printf("OMX_EmptyThisBuffer error\n");
}
else
{
// printf("omx_display_flush_buffer:idx=%d ptr=%p pnum=%d\n", buf_idx, (void *)st->buffers[buf_idx], (int)((void *)st->buffers[buf_idx] - (void *)st->buffers));
}
return 0;
}