forked from rellla/libcedarx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libcedarx.c
executable file
·1725 lines (1490 loc) · 48.9 KB
/
libcedarx.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
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2012-2013
*
* Authors: Wills Wang <wills.wang@hotmail.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <pthread.h>
#include <semaphore.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <errno.h>
#include "avheap.h"
#include "libve_typedef.h"
#include "libve.h"
#include "libve_adapter.h"
#include "cedardev_api.h"
#include "drv_display.h"
#include "libcedarx.h"
#define LIBCEDARX_VERSION "version 1.0.0"
#define VBV_FRAME_SIZE (8*1024*1024)
#define VBV_MAX_FRAME_NUM 64
#define VBV_MIN_FRAME_NUM 2
#define FBM_MAX_FRAME_NUM 64
#define MAX_SUPPORTED_VIDEO_WIDTH 1920
#define MAX_SUPPORTED_VIDEO_HEIGHT 1088
#define MAX_SUPPORTED_OUTPUT_WIDTH 1920
#define MAX_SUPPORTED_OUTPUT_HEIGHT 1080
typedef struct
{
Handle ve;
Handle fbm;
Handle vbv;
Handle sys;
u8* init_data;
u32 address;
u32 greedy;
int fd;
pthread_mutex_t mutex;
void (*request_buffer)(cedarx_picture_t * pic, void *sys);
void (*update_buffer)(cedarx_picture_t * pic, void *sys);
void (*release_buffer)(cedarx_picture_t * pic, void *sys);
void (*lock_buffer)(cedarx_picture_t * pic, void *sys);
void (*unlock_buffer)(cedarx_picture_t * pic, void *sys);
}cedarx_decoder_t;
typedef struct
{
int fd;
struct {
int enable;
int layer;
int start;
int init;
int top;
int last_id;
} info;
u32 idx;
pthread_mutex_t mutex;
}cedarx_display_t;
typedef struct STREAM_FRAME_T stream_frame_t;
struct STREAM_FRAME_T
{
vstream_data_t vstream;
stream_frame_t* next;
};
typedef struct
{
stream_frame_t* in_frames;
u32 write_index;
u32 frame_num;
u32 max_frame_num;
}stream_fifo_t;
typedef struct
{
stream_frame_t* head;
u32 frame_num;
}stream_queue_t;
typedef struct
{
u8* vbv_buf;
u8* vbv_buf_end;
u8* write_addr;
u32 valid_size;
u32 max_size;
stream_fifo_t frame_fifo;
stream_queue_t frame_queue;
pthread_mutex_t mutex;
}vbv_t;
typedef enum
{
FS_INVALID = 0,
FS_EMPTY = 1,
FS_BINDING = 2,
FS_DECODER_USING = 3,
FS_DECODER_DISCARD = 4,
FS_DECODER_SHARED = 5,
FS_DECODER_SHARE_DISCARD = 6
}frame_status_e;
typedef struct DISPLAY_FRAME_T display_frame_t;
struct DISPLAY_FRAME_T
{
vpicture_t vpicture;
frame_status_e status;
cedarx_picture_t picture;
display_frame_t* next;
};
typedef struct
{
display_frame_t* head;
u32 frame_num;
}display_queue_t;
typedef struct
{
u32 init_frame_num;
u32 exhausted;
u32 size_y[2];
u32 size_u[2];
u32 size_v[2];
u32 size_alpha[2];
_3d_mode_e mode;
display_queue_t empty_queue;
display_queue_t bind_queue;
display_queue_t decoded_queue;
display_frame_t frames[FBM_MAX_FRAME_NUM];
pthread_mutex_t mutex;
cedarx_decoder_t *decoder;
}fbm_t;
static cedarx_decoder_t *cedarx_decoder = NULL;
static cedarx_display_t *cedarx_display = NULL;
static void mem_init(int fd)
{
av_heap_init(fd);
}
static void mem_exit(void)
{
av_heap_release();
}
static void* mem_alloc(u32 size)
{
return malloc(size);
}
static void mem_free(void* p)
{
free(p);
}
void* mem_palloc(u32 size, u32 align)
{
void *p;
p = (void*)av_heap_alloc(size);
return p;
}
void mem_pfree(void* p)
{
av_heap_free(p);
}
static void mem_set(void* mem, u32 value, u32 size)
{
memset(mem, value, size);
}
static void mem_cpy(void* dst, void* src, u32 size)
{
memcpy(dst, src, size);
}
static void mem_flush_cache(u8* mem, u32 size)
{
}
static u32 mem_phy_addr(u32 virtual_addr)
{
if (virtual_addr)
return (u32)av_heap_physic_addr((void*)virtual_addr);
return 0;
}
static s32 sys_print(u8* func, u32 line, ...)
{
return 0;
}
static void sys_sleep(u32 ms)
{
usleep(ms * 1000);
}
IOS_t IOS =
{
//* Heap operation.
mem_alloc,
mem_free,
mem_palloc,
mem_pfree,
//* Memory operation.
mem_set,
mem_cpy,
mem_flush_cache,
mem_phy_addr,
//* MISC functions.
sys_print,
sys_sleep,
};
void ve_request(void)
{
cedarx_decoder_t* decoder = cedarx_decoder;
if (decoder && decoder->fd != -1) {
ioctl(decoder->fd, IOCTL_ENGINE_REQ, 0);
}
}
void ve_release(void)
{
cedarx_decoder_t* decoder = cedarx_decoder;
if (decoder && decoder->fd != -1) {
ioctl(decoder->fd, IOCTL_ENGINE_REL, 0);
}
}
static cedarx_result_e ve_init(void)
{
cedarx_decoder_t* decoder = cedarx_decoder;
if (decoder) {
decoder->fd = open("/dev/cedar_dev", O_RDWR);
if(decoder->fd != -1) {
cedarv_env_info_t cedarx_env_info;
ioctl(decoder->fd, IOCTL_GET_ENV_INFO, (unsigned long)&cedarx_env_info);
decoder->address = (unsigned int)mmap(NULL, 2048, PROT_READ | PROT_WRITE,
MAP_SHARED, decoder->fd, (unsigned long)cedarx_env_info.address_macc);
return CEDARX_RESULT_OK;
}
}
return CEDARX_RESULT_VE_FAILED;
}
static void ve_exit(void)
{
cedarx_decoder_t* decoder = cedarx_decoder;
if (decoder && decoder->fd != -1) {
munmap((void *)decoder->address, 2048);
close(decoder->fd);
}
}
static void ve_reset_hardware(void)
{
cedarx_decoder_t* decoder = cedarx_decoder;
if (decoder && decoder->fd != -1) {
ioctl(decoder->fd, IOCTL_RESET_VE, 0);
}
}
static void ve_enable_clock(u8 enable, u32 speed)
{
cedarx_decoder_t* decoder = cedarx_decoder;
if (decoder && decoder->fd != -1) {
if(enable) {
ioctl(decoder->fd, IOCTL_ENABLE_VE, 0);
ioctl(decoder->fd, IOCTL_SET_VE_FREQ, speed/1000000);
} else {
ioctl(decoder->fd, IOCTL_DISABLE_VE, 0);
}
}
}
static void ve_enable_intr(u8 enable)
{
/*
* cedar_dev.ko dose not support this operation, leave this method to be empty here.
*/
}
static s32 ve_wait_intr(void)
{
s32 status = 0;
cedarx_decoder_t* decoder = cedarx_decoder;
if (decoder && decoder->fd != -1) {
status = ioctl(decoder->fd, IOCTL_WAIT_VE, 2);
}
return (status - 1);
}
static u32 ve_get_reg_base_addr(void)
{
cedarx_decoder_t* decoder = cedarx_decoder;
if (decoder)
return decoder->address;
return 0;
}
static memtype_e ve_get_memtype(void)
{
return MEMTYPE_DDR3_32BITS; //* return the DRAM type.
}
IVEControl_t IVE =
{
ve_reset_hardware,
ve_enable_clock,
ve_enable_intr,
ve_wait_intr,
ve_get_reg_base_addr,
ve_get_memtype
};
static void vbv_enqueue_head(stream_queue_t* q, stream_frame_t* stream)
{
if (q && stream) {
stream->next = q->head;
q->head = stream;
q->frame_num++;
}
}
static void vbv_enqueue_tail(stream_queue_t* q, stream_frame_t* stream)
{
stream_frame_t* node;
if (q && stream) {
node = q->head;
if(node) {
while(node->next != NULL)
node = node->next;
node->next = stream;
stream->next = NULL;
} else {
q->head = stream;
stream->next = NULL;
}
q->frame_num ++;
}
}
static stream_frame_t* vbv_dequeue(stream_queue_t* q)
{
stream_frame_t* node = NULL;
if (q) {
node = q->head;
if(node) {
q->head = q->head->next;
node->next = NULL;
q->frame_num--;
}
}
return node;
}
static Handle vbv_init(void)
{
int i;
u8* vbv_buf;
vbv_t* vbv;
vbv = (vbv_t*)mem_alloc(sizeof(vbv_t));
if (vbv) {
mem_set(vbv, 0, sizeof(vbv_t));
vbv->frame_fifo.in_frames = (stream_frame_t*)mem_alloc(VBV_MAX_FRAME_NUM * sizeof(stream_frame_t));
if (!vbv->frame_fifo.in_frames) {
mem_free(vbv);
return NULL;
}
mem_set(vbv->frame_fifo.in_frames, 0, VBV_MAX_FRAME_NUM * sizeof(stream_frame_t));
for(i = 0; i < VBV_MAX_FRAME_NUM; i++)
{
vbv->frame_fifo.in_frames[i].vstream.id = i;
}
vbv_buf = (u8*)mem_palloc(VBV_FRAME_SIZE, 1024);
if (!vbv_buf) {
mem_free(vbv);
mem_free(vbv->frame_fifo.in_frames);
return NULL;
}
vbv->vbv_buf = vbv_buf;
vbv->vbv_buf_end = vbv_buf + VBV_FRAME_SIZE;
vbv->max_size = VBV_FRAME_SIZE;
vbv->write_addr = vbv_buf;
vbv->valid_size = 0;
vbv->frame_fifo.frame_num = 0;
vbv->frame_fifo.write_index = 0;
vbv->frame_fifo.max_frame_num = VBV_MAX_FRAME_NUM;
vbv->frame_queue.frame_num = 0;
vbv->frame_queue.head = NULL;
pthread_mutex_init(&vbv->mutex, NULL);
return (Handle)vbv;
}
return NULL;
}
static void vbv_exit(Handle h)
{
vbv_t* vbv = (vbv_t*)h;
if (vbv) {
pthread_mutex_destroy(&vbv->mutex);
if (vbv->frame_fifo.in_frames) {
mem_free(vbv->frame_fifo.in_frames);
}
if (vbv->vbv_buf) {
mem_pfree(vbv->vbv_buf);
}
mem_free(vbv);
}
}
static cedarx_result_e vbv_check_stream_frame(Handle h)
{
vbv_t* vbv = (vbv_t*)h;
if (vbv->frame_fifo.frame_num > VBV_MIN_FRAME_NUM) {
return CEDARX_RESULT_OK;
}
return CEDARX_RESULT_VBV_BUFFER_EMPTY;
}
static cedarx_result_e vbv_add_stream_frame(vstream_data_t* stream, Handle h)
{
vbv_t* vbv = (vbv_t*)h;
stream_frame_t* frame;
u32 write_index;
u8* new_write_addr;
if (!stream || !vbv)
return CEDARX_RESULT_NO_INIT;
if (vbv->frame_fifo.frame_num >= vbv->frame_fifo.max_frame_num) {
printf("Warning: The fifo is full!\n");
return CEDARX_RESULT_VBV_BUFFER_FULL;
}
if (vbv->valid_size >= vbv->max_size) {
printf("Warning: The buffer is full!\n");
return CEDARX_RESULT_VBV_BUFFER_FULL;
}
if (stream->length + vbv->valid_size > vbv->max_size) {
printf("Warning: There are not enough memory!\n");
return CEDARX_RESULT_VBV_BUFFER_NO_ENOUGH;
}
pthread_mutex_lock(&vbv->mutex);
new_write_addr = vbv->write_addr + stream->length;
if (new_write_addr >= vbv->vbv_buf_end) {
u32 size = vbv->vbv_buf_end - vbv->write_addr;
mem_cpy(vbv->write_addr, stream->data, size);
mem_cpy(vbv->vbv_buf, stream->data + size, stream->length - size);
new_write_addr -= vbv->max_size;
} else {
mem_cpy(vbv->write_addr, stream->data, stream->length);
}
write_index = vbv->frame_fifo.write_index;
frame = &vbv->frame_fifo.in_frames[write_index];
frame->vstream.data = stream->data;
frame->vstream.length = stream->length;
frame->vstream.pts = stream->pts;
frame->vstream.pcr = stream->pcr;
frame->vstream.valid = stream->valid;
frame->vstream.stream_type = stream->stream_type;
frame->vstream.pict_prop = stream->pict_prop;
frame->vstream.data = vbv->write_addr;
write_index ++;
if (write_index >= vbv->frame_fifo.max_frame_num) {
write_index = 0;
}
vbv->frame_fifo.write_index = write_index;
vbv->frame_fifo.frame_num++;
vbv->valid_size += stream->length;
vbv->write_addr = new_write_addr;
vbv_enqueue_tail(&vbv->frame_queue, frame); //* add this frame to the queue tail.
pthread_mutex_unlock(&vbv->mutex);
return CEDARX_RESULT_OK;
}
static vstream_data_t* vbv_request_stream_frame(Handle h)
{
vbv_t* vbv = (vbv_t*)h;
stream_frame_t* frame;
vstream_data_t* stream = NULL;
if (vbv) {
pthread_mutex_lock(&vbv->mutex);
frame = vbv_dequeue(&vbv->frame_queue);
if (frame) {
stream = &frame->vstream;
}
pthread_mutex_unlock(&vbv->mutex);
}
return stream;
}
static void vbv_return_stream_frame(vstream_data_t* stream, Handle h)
{
int i;
vbv_t* vbv = (vbv_t*)h;
stream_frame_t* frame = NULL;
if (vbv && stream) {
if (vbv->frame_fifo.frame_num > 0) {
pthread_mutex_lock(&vbv->mutex);
for(i = 0; i < vbv->frame_fifo.max_frame_num; i++) {
frame = &vbv->frame_fifo.in_frames[i];
if (stream == &frame->vstream) {
vbv_enqueue_head(&vbv->frame_queue, frame);
}
}
pthread_mutex_unlock(&vbv->mutex);
}
}
}
static void vbv_flush_stream_frame(vstream_data_t* stream, Handle h)
{
int i;
vbv_t* vbv = (vbv_t*)h;
stream_frame_t* frame = NULL;
if (vbv && stream) {
if (vbv->frame_fifo.frame_num > 0) {
pthread_mutex_lock(&vbv->mutex);
for(i = 0; i < vbv->frame_fifo.max_frame_num; i++) {
frame = &vbv->frame_fifo.in_frames[i];
if (stream == &frame->vstream) {
vbv->frame_fifo.frame_num--;
vbv->valid_size -= stream->length;
}
}
pthread_mutex_unlock(&vbv->mutex);
}
}
}
static u8* vbv_get_base_addr(Handle h)
{
vbv_t* vbv = (vbv_t*)h;
if (vbv) {
return vbv->vbv_buf;
}
return NULL;
}
static u32 vbv_get_buffer_size(Handle h)
{
vbv_t* vbv = (vbv_t*)h;
if(vbv) {
return vbv->max_size;
}
return 0;
}
IVBV_t IVBV =
{
vbv_request_stream_frame,
vbv_return_stream_frame,
vbv_flush_stream_frame,
vbv_get_base_addr,
vbv_get_buffer_size
};
static void fbm_enqueue_head(display_queue_t* q, display_frame_t* frame)
{
if (q && frame) {
frame->next = q->head;
q->head = frame;
q->frame_num++;
}
}
static void fbm_enqueue_tail(display_queue_t* q, display_frame_t* frame)
{
display_frame_t* node;
if (q && frame) {
node = q->head;
if(node) {
while(node->next != NULL)
node = node->next;
node->next = frame;
} else {
q->head = frame;
}
frame->next = NULL;
q->frame_num++;
}
}
static display_frame_t* fbm_dequeue(display_queue_t* q)
{
display_frame_t* node = NULL;
if (q) {
node = q->head;
if(node) {
q->head = q->head->next;
node->next = NULL;
q->frame_num--;
}
}
return node;
}
static display_frame_t* fbm_pick(display_queue_t* q, Handle sys)
{
display_frame_t *node, *frame;
if (q && sys) {
node = q->head;
if(node) {
if (node->picture.sys == sys) {
q->head = node->next;
node->next = NULL;
q->frame_num--;
return node;
} else {
while(node->next != NULL) {
frame = node->next;
if (frame->picture.sys == sys) {
node->next = frame->next;
frame->next = NULL;
q->frame_num--;
return frame;
}
node = frame;
}
}
}
}
return NULL;
}
static u8 fbm_pointer_to_index(vpicture_t* frame, Handle h)
{
u8 i;
fbm_t* fbm = (fbm_t*)h;
if(fbm) {
for(i = 0; i < FBM_MAX_FRAME_NUM; i++) {
if(&fbm->frames[i].vpicture == frame)
return i;
}
}
return 0xff;
}
static void fbm_free_frame_buffer(cedarx_picture_t* picture)
{
if(picture->y[0] && picture->size_y[0]) {
mem_pfree(picture->y[0]);
picture->y[0] = NULL;
picture->size_y[0] = 0;
}
if(picture->u[0] && picture->size_u[0]) {
mem_pfree(picture->u[0]);
picture->u[0] = NULL;
picture->size_u[0] = 0;
}
if(picture->v[0] && picture->size_v[0]) {
mem_pfree(picture->v[0]);
picture->v[0] = NULL;
picture->size_v[0] = 0;
}
if(picture->alpha[0] && picture->size_alpha[0]) {
mem_pfree(picture->alpha[0]);
picture->alpha[0] = NULL;
picture->size_alpha[0] = 0;
}
if(picture->y[1] && picture->size_y[1]) {
mem_pfree(picture->y[1]);
picture->y[1] = NULL;
picture->size_y[1] = 0;
}
if(picture->u[1] && picture->size_u[1]) {
mem_pfree(picture->u[1]);
picture->u[1] = NULL;
picture->size_u[1] = 0;
}
if(picture->v[1] && picture->size_v[1]) {
mem_pfree(picture->v[1]);
picture->v[1] = NULL;
picture->size_v[1] = 0;
}
if(picture->alpha[1] && picture->size_alpha[1]) {
mem_pfree(picture->alpha[1]);
picture->alpha[1] = NULL;
picture->size_alpha[1] = 0;
}
}
static s32 fbm_alloc_frame_buffer(cedarx_picture_t* picture)
{
cedarx_decoder_t* decoder = cedarx_decoder;
if (decoder && decoder->fbm) {
fbm_t* fbm = decoder->fbm;
if (picture->size_y[0] < fbm->size_y[0])
printf("Warning: need 0x%x bytes but just request 0x%x bytes at %s:%s:%d!!!!\n", \
fbm->size_y[0], picture->size_y[0], __FILE__, __FUNCTION__, __LINE__);
if (picture->size_u[0] < fbm->size_u[0])
printf("Warning: need 0x%x bytes but just request 0x%x bytes at %s:%s:%d!!!!\n", \
fbm->size_u[0], picture->size_u[0], __FILE__, __FUNCTION__, __LINE__);
if (picture->size_v[0] < fbm->size_v[0])
printf("Warning: need 0x%x bytes but just request 0x%x bytes at %s:%s:%d!!!!\n", \
fbm->size_v[0], picture->size_v[0], __FILE__, __FUNCTION__, __LINE__);
if (picture->size_alpha[0] < fbm->size_alpha[0])
printf("Warning: need 0x%x bytes but just request 0x%x bytes at %s:%s:%d!!!!\n", \
fbm->size_alpha[0], picture->size_alpha[0], __FILE__, __FUNCTION__, __LINE__);
if (picture->size_y[1] < fbm->size_y[1])
printf("Warning: need 0x%x bytes but just request 0x%x bytes at %s:%s:%d!!!!\n", \
fbm->size_y[1], picture->size_y[1], __FILE__, __FUNCTION__, __LINE__);
if (picture->size_u[1] < fbm->size_u[1])
printf("Warning: need 0x%x bytes but just request 0x%x bytes at %s:%s:%d!!!!\n", \
fbm->size_u[1], picture->size_u[1], __FILE__, __FUNCTION__, __LINE__);
if (picture->size_v[1] < fbm->size_v[1])
printf("Warning: need 0x%x bytes but just request 0x%x bytes at %s:%s:%d!!!!\n", \
fbm->size_v[1], picture->size_v[1], __FILE__, __FUNCTION__, __LINE__);
if (picture->size_alpha[1] < fbm->size_alpha[1])
printf("Warning: need 0x%x bytes but just request 0x%x bytes at %s:%s:%d!!!!\n", \
fbm->size_alpha[1], picture->size_alpha[1], __FILE__, __FUNCTION__, __LINE__);
}
if(picture->size_y[0]) {
picture->y[0] = (u8*)mem_palloc(picture->size_y[0], 0);
if(!picture->y[0])
goto err;
}
if(picture->size_u[0]) {
picture->u[0] = (u8*)mem_palloc(picture->size_u[0], 0);
if(!picture->u[0])
goto err;
}
if(picture->size_v[0]) {
picture->v[0] = (u8*)mem_palloc(picture->size_v[0], 0);
if(!picture->v[0])
goto err;
}
if(picture->size_alpha[0]) {
picture->alpha[0] = (u8*)mem_palloc(picture->size_alpha[0], 0);
if(!picture->alpha[0])
goto err;
}
if(picture->size_y[1]) {
picture->y[1] = (u8*)mem_palloc(picture->size_y[1], 0);
if(!picture->y[1])
goto err;
}
if(picture->size_u[1]) {
picture->u[1] = (u8*)mem_palloc(picture->size_u[1], 0);
if(!picture->u[1])
goto err;
}
if(picture->size_v[1]) {
picture->v[1] = (u8*)mem_palloc(picture->size_v[1], 0);
if(!picture->v[1])
goto err;
}
if(picture->size_alpha[1]) {
picture->alpha[1] = (u8*)mem_palloc(picture->size_alpha[1], 0);
if(!picture->alpha[1])
goto err;
}
return CEDARX_RESULT_OK;
err:
fbm_free_frame_buffer(picture);
return CEDARX_RESULT_NO_ENOUGH_MEMORY;
}
static Handle fbm_init(u32 max_frame_num,
u32 min_frame_num, u32 size_y[2],
u32 size_u[2], u32 size_v[2],
u32 size_alpha[2], _3d_mode_e out_3d_mode,
pixel_format_e format, void* parent)
{
s32 i;
fbm_t* fbm;
cedarx_decoder_t* decoder = cedarx_decoder;
// libve_io_ctrl(LIBVE_COMMAND_GET_PARENT, (u32)&decoder, parent);
// if (!decoder)
// return NULL;
fbm = (fbm_t*) mem_alloc(sizeof(fbm_t));
if(!fbm)
return NULL;
mem_set(fbm, 0, sizeof(fbm_t));
fbm->size_y[0] = size_y[0];
fbm->size_u[0] = size_u[0];
fbm->mode = out_3d_mode;
if (fbm->mode == _3D_MODE_DOUBLE_STREAM) {
fbm->size_y[1] = size_y[1];
fbm->size_u[1] = size_u[1];
}
for(i = 0; i < FBM_MAX_FRAME_NUM; i++) {
fbm->frames[i].status = FS_EMPTY;
fbm->frames[i].vpicture.id = i;
fbm->frames[i].vpicture._3d_mode = fbm->mode;
fbm->frames[i].vpicture.size_y = fbm->size_y[0];
fbm->frames[i].vpicture.size_u = fbm->size_u[0];
fbm->frames[i].vpicture.size_v = fbm->size_v[0];
fbm->frames[i].vpicture.size_alpha = fbm->size_alpha[0];
fbm->frames[i].vpicture.size_y2 = fbm->size_y[1];
fbm->frames[i].vpicture.size_u2 = fbm->size_u[1];
fbm->frames[i].vpicture.size_v2 = fbm->size_v[1];
fbm->frames[i].vpicture.size_alpha2 = fbm->size_alpha[1];
if(i < max_frame_num) {
fbm_enqueue_tail(&fbm->empty_queue, &fbm->frames[i]);
fbm->init_frame_num ++;
}
}
fbm->decoder = decoder;
decoder->fbm = fbm;
pthread_mutex_init(&fbm->mutex, NULL);
return (Handle)fbm;
}
static void fbm_release(Handle h, void* parent)
{
fbm_t* fbm = (fbm_t*)h;
cedarx_decoder_t* decoder;
if(fbm) {
pthread_mutex_destroy(&fbm->mutex);
decoder = fbm->decoder;
decoder->fbm = NULL;
mem_free(fbm);
}
}
static vpicture_t* fbm_request_decoder_frame(Handle h)
{
fbm_t* fbm;
display_frame_t* frame_info;
vpicture_t* vpicture = NULL;
cedarx_picture_t *picture;
fbm = (fbm_t*)h;
if(fbm && fbm->decoder && fbm->decoder->request_buffer) {
pthread_mutex_lock(&fbm->mutex);
cedarx_picture_t pic;
memset(&pic, 0, sizeof(cedarx_picture_t));
if (fbm->decoder->greedy && !fbm->exhausted) {
frame_info = fbm_dequeue(&fbm->empty_queue);
if(frame_info) {
fbm->decoder->request_buffer(&pic, fbm->decoder->sys);
if (pic.sys) {
picture = &frame_info->picture;
vpicture = &frame_info->vpicture;
vpicture->y = pic.y[0];
vpicture->u = pic.u[0];
vpicture->v = pic.v[0];
vpicture->alpha = pic.alpha[0];
vpicture->y2 = pic.y[1];
vpicture->u2 = pic.u[1];
vpicture->v2 = pic.v[1];
vpicture->alpha2 = pic.alpha[1];
picture->sys = pic.sys;
frame_info->status = FS_DECODER_USING;
} else {
fbm_enqueue_head(&fbm->empty_queue, frame_info);
}
} else {
fbm->exhausted = 1;
}
} else {
fbm->decoder->request_buffer(&pic, fbm->decoder->sys);
if (pic.sys) {
frame_info = fbm_pick(&fbm->bind_queue, pic.sys);
if(frame_info) {
vpicture = &frame_info->vpicture;
frame_info->status = FS_DECODER_USING;
} else {
frame_info = fbm_dequeue(&fbm->empty_queue);
if(!frame_info) {
if (fbm->init_frame_num < FBM_MAX_FRAME_NUM) {
frame_info = &fbm->frames[fbm->init_frame_num];
fbm->init_frame_num ++;
}
}
if(frame_info) {
picture = &frame_info->picture;
vpicture = &frame_info->vpicture;
vpicture->y = pic.y[0];
vpicture->u = pic.u[0];
vpicture->v = pic.v[0];
vpicture->alpha = pic.alpha[0];
vpicture->y2 = pic.y[1];
vpicture->u2 = pic.u[1];
vpicture->v2 = pic.v[1];
vpicture->alpha2 = pic.alpha[1];
picture->sys = pic.sys;
frame_info->status = FS_DECODER_USING;
} else {
if (fbm->decoder->release_buffer)
fbm->decoder->release_buffer(&pic, fbm->decoder->sys);
}
}