forked from arco/android_hardware_qcom_media-legacy
/
omx_video_base.cpp
4756 lines (4322 loc) · 149 KB
/
omx_video_base.cpp
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) 2010-2012, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of The Linux Foundation nor
the names of its contributors may be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------*/
/*============================================================================
O p e n M A X w r a p p e r s
O p e n M A X C o r e
*//** @file omx_video_base.cpp
This module contains the implementation of the OpenMAX core & component.
*//*========================================================================*/
//////////////////////////////////////////////////////////////////////////////
// Include Files
//////////////////////////////////////////////////////////////////////////////
#include <string.h>
#include "omx_video_base.h"
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/prctl.h>
#ifdef _ANDROID_ICS_
#include <media/hardware/HardwareAPI.h>
#include <gralloc_priv.h>
#endif
#ifndef _ANDROID_
#include <glib.h>
#define strlcpy g_strlcpy
#endif
#define H264_SUPPORTED_WIDTH (480)
#define H264_SUPPORTED_HEIGHT (368)
#define MPEG4_SUPPORTED_WIDTH (480)
#define MPEG4_SUPPORTED_HEIGHT (368)
#define VC1_SP_MP_START_CODE 0xC5000000
#define VC1_SP_MP_START_CODE_MASK 0xFF000000
#define VC1_AP_START_CODE 0x00000100
#define VC1_AP_START_CODE_MASK 0xFFFFFF00
#define VC1_STRUCT_C_PROFILE_MASK 0xF0
#define VC1_STRUCT_B_LEVEL_MASK 0xE0000000
#define VC1_SIMPLE_PROFILE 0
#define VC1_MAIN_PROFILE 1
#define VC1_ADVANCE_PROFILE 3
#define VC1_SIMPLE_PROFILE_LOW_LEVEL 0
#define VC1_SIMPLE_PROFILE_MED_LEVEL 2
#define VC1_STRUCT_C_LEN 4
#define VC1_STRUCT_C_POS 8
#define VC1_STRUCT_A_POS 12
#define VC1_STRUCT_B_POS 24
#define VC1_SEQ_LAYER_SIZE 36
#define IS_NOT_ALIGNED( num, to) (num & (to-1))
#define ALIGN( num, to ) (((num) + (to-1)) & (~(to-1)))
#define SZ_2K (2048)
typedef struct OMXComponentCapabilityFlagsType
{
////////////////// OMX COMPONENT CAPABILITY RELATED MEMBERS
OMX_BOOL iIsOMXComponentMultiThreaded;
OMX_BOOL iOMXComponentSupportsExternalOutputBufferAlloc;
OMX_BOOL iOMXComponentSupportsExternalInputBufferAlloc;
OMX_BOOL iOMXComponentSupportsMovableInputBuffers;
OMX_BOOL iOMXComponentSupportsPartialFrames;
OMX_BOOL iOMXComponentUsesNALStartCodes;
OMX_BOOL iOMXComponentCanHandleIncompleteFrames;
OMX_BOOL iOMXComponentUsesFullAVCFrames;
} OMXComponentCapabilityFlagsType;
#define OMX_COMPONENT_CAPABILITY_TYPE_INDEX 0xFF7A347
#ifdef OUTPUT_BUFFER_LOG
extern FILE *outputBufferFile1;
#endif
void* message_thread(void *input)
{
omx_video* omx = reinterpret_cast<omx_video*>(input);
unsigned char id;
int n;
DEBUG_PRINT_LOW("omx_venc: message thread start\n");
prctl(PR_SET_NAME, (unsigned long)"VideoEncMsgThread", 0, 0, 0);
while(1)
{
n = read(omx->m_pipe_in, &id, 1);
if(0 == n)
{
break;
}
if(1 == n)
{
omx->process_event_cb(omx, id);
}
#ifdef QLE_BUILD
if(n < 0) break;
#else
if((n < 0) && (errno != EINTR)) break;
#endif
}
DEBUG_PRINT_LOW("omx_venc: message thread stop\n");
return 0;
}
void post_message(omx_video *omx, unsigned char id)
{
DEBUG_PRINT_LOW("omx_venc: post_message %d\n", id);
write(omx->m_pipe_out, &id, 1);
}
// omx_cmd_queue destructor
omx_video::omx_cmd_queue::~omx_cmd_queue()
{
// Nothing to do
}
// omx cmd queue constructor
omx_video::omx_cmd_queue::omx_cmd_queue(): m_read(0),m_write(0),m_size(0)
{
memset(m_q,0,sizeof(omx_event)*OMX_CORE_CONTROL_CMDQ_SIZE);
}
// omx cmd queue insert
bool omx_video::omx_cmd_queue::insert_entry(unsigned p1, unsigned p2, unsigned id)
{
bool ret = true;
if(m_size < OMX_CORE_CONTROL_CMDQ_SIZE)
{
m_q[m_write].id = id;
m_q[m_write].param1 = p1;
m_q[m_write].param2 = p2;
m_write++;
m_size ++;
if(m_write >= OMX_CORE_CONTROL_CMDQ_SIZE)
{
m_write = 0;
}
}
else
{
ret = false;
DEBUG_PRINT_ERROR("ERROR!!! Command Queue Full\n");
}
return ret;
}
// omx cmd queue pop
bool omx_video::omx_cmd_queue::pop_entry(unsigned *p1, unsigned *p2, unsigned *id)
{
bool ret = true;
if(m_size > 0)
{
*id = m_q[m_read].id;
*p1 = m_q[m_read].param1;
*p2 = m_q[m_read].param2;
// Move the read pointer ahead
++m_read;
--m_size;
if(m_read >= OMX_CORE_CONTROL_CMDQ_SIZE)
{
m_read = 0;
}
}
else
{
ret = false;
}
return ret;
}
// Retrieve the first mesg type in the queue
unsigned omx_video::omx_cmd_queue::get_q_msg_type()
{
return m_q[m_read].id;
}
#ifdef _ANDROID_
VideoHeap::VideoHeap(int fd, size_t size, void* base)
{
// dup file descriptor, map once, use pmem
init(dup(fd), base, size, 0 , MEM_DEVICE);
}
#endif // _ANDROID_
/* ======================================================================
FUNCTION
omx_venc::omx_venc
DESCRIPTION
Constructor
PARAMETERS
None
RETURN VALUE
None.
========================================================================== */
omx_video::omx_video(): m_state(OMX_StateInvalid),
m_app_data(NULL),
m_inp_mem_ptr(NULL),
m_out_mem_ptr(NULL),
m_pInput_pmem(NULL),
m_pOutput_pmem(NULL),
#ifdef USE_ION
m_pInput_ion(NULL),
m_pOutput_ion(NULL),
#endif
pending_input_buffers(0),
pending_output_buffers(0),
m_out_bm_count(0),
m_inp_bm_count(0),
m_flags(0),
m_event_port_settings_sent(false),
output_flush_progress (false),
input_flush_progress (false),
input_use_buffer (false),
output_use_buffer (false),
m_use_input_pmem(OMX_FALSE),
m_use_output_pmem(OMX_FALSE),
m_etb_count(0),
m_fbd_count(0),
m_error_propogated(false),
m_input_msg_id(OMX_COMPONENT_GENERATE_ETB),
psource_frame(NULL),
pdest_frame(NULL),
c2d_opened(false),
secure_session(false)
{
DEBUG_PRINT_HIGH("\n omx_video(): Inside Constructor()");
memset(&m_cmp,0,sizeof(m_cmp));
memset(&m_pCallbacks,0,sizeof(m_pCallbacks));
secure_color_format = (int) OMX_COLOR_FormatYUV420SemiPlanar;
pthread_mutex_init(&m_lock, NULL);
sem_init(&m_cmd_lock,0,0);
}
/* ======================================================================
FUNCTION
omx_venc::~omx_venc
DESCRIPTION
Destructor
PARAMETERS
None
RETURN VALUE
None.
========================================================================== */
omx_video::~omx_video()
{
DEBUG_PRINT_HIGH("\n ~omx_video(): Inside Destructor()");
if(m_pipe_in) close(m_pipe_in);
if(m_pipe_out) close(m_pipe_out);
DEBUG_PRINT_HIGH("omx_video: Waiting on Msg Thread exit\n");
pthread_join(msg_thread_id,NULL);
DEBUG_PRINT_HIGH("omx_video: Waiting on Async Thread exit\n");
pthread_join(async_thread_id,NULL);
pthread_mutex_destroy(&m_lock);
sem_destroy(&m_cmd_lock);
DEBUG_PRINT_HIGH("\n m_etb_count = %u, m_fbd_count = %u\n", m_etb_count,
m_fbd_count);
DEBUG_PRINT_HIGH("omx_video: Destructor exit\n");
DEBUG_PRINT_HIGH("Exiting 7x30 OMX Video Encoder ...\n");
}
/* ======================================================================
FUNCTION
omx_venc::OMXCntrlProcessMsgCb
DESCRIPTION
IL Client callbacks are generated through this routine. The decoder
provides the thread context for this routine.
PARAMETERS
ctxt -- Context information related to the self.
id -- Event identifier. This could be any of the following:
1. Command completion event
2. Buffer done callback event
3. Frame done callback event
RETURN VALUE
None.
========================================================================== */
void omx_video::process_event_cb(void *ctxt, unsigned char id)
{
unsigned p1; // Parameter - 1
unsigned p2; // Parameter - 2
unsigned ident;
unsigned qsize=0; // qsize
omx_video *pThis = (omx_video *) ctxt;
if(!pThis)
{
DEBUG_PRINT_ERROR("ERROR:ProcessMsgCb:Context is incorrect; bailing out\n");
return;
}
// Protect the shared queue data structure
do
{
/*Read the message id's from the queue*/
pthread_mutex_lock(&pThis->m_lock);
qsize = pThis->m_cmd_q.m_size;
if(qsize)
{
pThis->m_cmd_q.pop_entry(&p1,&p2,&ident);
}
if(qsize == 0)
{
qsize = pThis->m_ftb_q.m_size;
if(qsize)
{
pThis->m_ftb_q.pop_entry(&p1,&p2,&ident);
}
}
if(qsize == 0)
{
qsize = pThis->m_etb_q.m_size;
if(qsize)
{
pThis->m_etb_q.pop_entry(&p1,&p2,&ident);
}
}
pthread_mutex_unlock(&pThis->m_lock);
/*process message if we have one*/
if(qsize > 0)
{
id = ident;
switch(id)
{
case OMX_COMPONENT_GENERATE_EVENT:
if(pThis->m_pCallbacks.EventHandler)
{
switch(p1)
{
case OMX_CommandStateSet:
pThis->m_state = (OMX_STATETYPE) p2;
DEBUG_PRINT_LOW("Process -> state set to %d \n", pThis->m_state);
pThis->m_pCallbacks.EventHandler(&pThis->m_cmp, pThis->m_app_data,
OMX_EventCmdComplete, p1, p2, NULL);
break;
case OMX_EventError:
DEBUG_PRINT_ERROR("\nERROR: OMX_EventError: p2 = %d\n", p2);
if(p2 == OMX_ErrorHardware)
{
pThis->m_pCallbacks.EventHandler(&pThis->m_cmp, pThis->m_app_data,
OMX_EventError,OMX_ErrorHardware,0,NULL);
}
else
{
pThis->m_pCallbacks.EventHandler(&pThis->m_cmp, pThis->m_app_data,
OMX_EventError, p2, NULL, NULL );
}
break;
case OMX_CommandPortDisable:
DEBUG_PRINT_LOW("Process -> Port %d set to PORT_STATE_DISABLED" \
"state \n", p2);
pThis->m_pCallbacks.EventHandler(&pThis->m_cmp, pThis->m_app_data,
OMX_EventCmdComplete, p1, p2, NULL );
break;
case OMX_CommandPortEnable:
DEBUG_PRINT_LOW("Process ->Port %d set PORT_STATE_ENABLED state\n" \
, p2);
pThis->m_pCallbacks.EventHandler(&pThis->m_cmp, pThis->m_app_data,\
OMX_EventCmdComplete, p1, p2, NULL );
break;
default:
DEBUG_PRINT_LOW("\n process_event_cb forwarding EventCmdComplete %d \n", p1);
pThis->m_pCallbacks.EventHandler(&pThis->m_cmp, pThis->m_app_data,
OMX_EventCmdComplete, p1, p2, NULL );
break;
}
}
else
{
DEBUG_PRINT_ERROR("ERROR: ProcessMsgCb NULL callbacks\n");
}
break;
case OMX_COMPONENT_GENERATE_ETB_OPQ:
DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_ETB_OPQ\n");
if(pThis->empty_this_buffer_opaque((OMX_HANDLETYPE)p1,\
(OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone)
{
DEBUG_PRINT_ERROR("\nERROR: ETBProxy() failed!\n");
pThis->omx_report_error ();
}
break;
case OMX_COMPONENT_GENERATE_ETB:
DEBUG_PRINT_LOW("OMX_COMPONENT_GENERATE_ETB\n");
if(pThis->empty_this_buffer_proxy((OMX_HANDLETYPE)p1,\
(OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone)
{
DEBUG_PRINT_ERROR("\nERROR: ETBProxy() failed!\n");
pThis->omx_report_error ();
}
break;
case OMX_COMPONENT_GENERATE_FTB:
if( pThis->fill_this_buffer_proxy((OMX_HANDLETYPE)p1,\
(OMX_BUFFERHEADERTYPE *)p2) != OMX_ErrorNone)
{
DEBUG_PRINT_ERROR("\nERROR: FTBProxy() failed!\n");
pThis->omx_report_error ();
}
break;
case OMX_COMPONENT_GENERATE_COMMAND:
pThis->send_command_proxy(&pThis->m_cmp,(OMX_COMMANDTYPE)p1,\
(OMX_U32)p2,(OMX_PTR)NULL);
break;
case OMX_COMPONENT_GENERATE_EBD:
if( pThis->empty_buffer_done(&pThis->m_cmp,
(OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone)
{
DEBUG_PRINT_ERROR("\nERROR: empty_buffer_done() failed!\n");
pThis->omx_report_error ();
}
break;
case OMX_COMPONENT_GENERATE_FBD:
if( pThis->fill_buffer_done(&pThis->m_cmp,
(OMX_BUFFERHEADERTYPE *)p1) != OMX_ErrorNone )
{
DEBUG_PRINT_ERROR("\nERROR: fill_buffer_done() failed!\n");
pThis->omx_report_error ();
}
break;
case OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH:
pThis->input_flush_progress = false;
DEBUG_PRINT_HIGH("\nm_etb_count at i/p flush = %u", m_etb_count);
m_etb_count = 0;
if(pThis->m_pCallbacks.EventHandler)
{
/*Check if we need generate event for Flush done*/
if(BITMASK_PRESENT(&pThis->m_flags,
OMX_COMPONENT_INPUT_FLUSH_PENDING))
{
BITMASK_CLEAR (&pThis->m_flags,OMX_COMPONENT_INPUT_FLUSH_PENDING);
pThis->m_pCallbacks.EventHandler(&pThis->m_cmp, pThis->m_app_data,
OMX_EventCmdComplete,OMX_CommandFlush,
PORT_INDEX_IN,NULL );
}
else if(BITMASK_PRESENT(&pThis->m_flags,
OMX_COMPONENT_IDLE_PENDING))
{
if(!pThis->output_flush_progress)
{
DEBUG_PRINT_LOW("\n dev_stop called after input flush complete\n");
if(dev_stop() != 0)
{
DEBUG_PRINT_ERROR("\nERROR: dev_stop() failed in i/p flush!\n");
pThis->omx_report_error ();
}
}
}
}
break;
case OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH:
pThis->output_flush_progress = false;
DEBUG_PRINT_HIGH("\nm_fbd_count at o/p flush = %u", m_fbd_count);
m_fbd_count = 0;
if(pThis->m_pCallbacks.EventHandler)
{
/*Check if we need generate event for Flush done*/
if(BITMASK_PRESENT(&pThis->m_flags,
OMX_COMPONENT_OUTPUT_FLUSH_PENDING))
{
BITMASK_CLEAR (&pThis->m_flags,OMX_COMPONENT_OUTPUT_FLUSH_PENDING);
pThis->m_pCallbacks.EventHandler(&pThis->m_cmp, pThis->m_app_data,
OMX_EventCmdComplete,OMX_CommandFlush,
PORT_INDEX_OUT,NULL );
}
else if(BITMASK_PRESENT(&pThis->m_flags ,OMX_COMPONENT_IDLE_PENDING))
{
DEBUG_PRINT_LOW("\n dev_stop called after Output flush complete\n");
if(!pThis->input_flush_progress)
{
if(dev_stop() != 0)
{
DEBUG_PRINT_ERROR("\nERROR: dev_stop() failed in o/p flush!\n");
pThis->omx_report_error ();
}
}
}
}
break;
case OMX_COMPONENT_GENERATE_START_DONE:
DEBUG_PRINT_LOW("\n OMX_COMPONENT_GENERATE_START_DONE msg");
if(pThis->m_pCallbacks.EventHandler)
{
DEBUG_PRINT_LOW("\n OMX_COMPONENT_GENERATE_START_DONE Success");
if(BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_EXECUTE_PENDING))
{
DEBUG_PRINT_LOW("\n OMX_COMPONENT_GENERATE_START_DONE Move to \
executing");
// Send the callback now
BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_EXECUTE_PENDING);
pThis->m_state = OMX_StateExecuting;
pThis->m_pCallbacks.EventHandler(&pThis->m_cmp, pThis->m_app_data,
OMX_EventCmdComplete,OMX_CommandStateSet,
OMX_StateExecuting, NULL);
}
else if(BITMASK_PRESENT(&pThis->m_flags,
OMX_COMPONENT_PAUSE_PENDING))
{
if(dev_pause())
{
DEBUG_PRINT_ERROR("\nERROR: dev_pause() failed in Start Done!\n");
pThis->omx_report_error ();
}
}
else if (BITMASK_PRESENT(&pThis->m_flags,
OMX_COMPONENT_LOADED_START_PENDING))
{
if(dev_loaded_start_done())
{
DEBUG_PRINT_LOW("successful loaded Start Done!");
}
else
{
DEBUG_PRINT_ERROR("ERROR: failed in loaded Start Done!");
pThis->omx_report_error ();
}
BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_LOADED_START_PENDING);
}
else
{
DEBUG_PRINT_ERROR("\nERROR: unknown flags=%x\n",pThis->m_flags);
}
}
else
{
DEBUG_PRINT_LOW("\n Event Handler callback is NULL");
}
break;
case OMX_COMPONENT_GENERATE_PAUSE_DONE:
DEBUG_PRINT_LOW("\n OMX_COMPONENT_GENERATE_PAUSE_DONE msg");
if(pThis->m_pCallbacks.EventHandler)
{
if(BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_PAUSE_PENDING))
{
//Send the callback now
pThis->complete_pending_buffer_done_cbs();
DEBUG_PRINT_LOW("omx_video::process_event_cb() Sending PAUSE complete after all pending EBD/FBD\n");
BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_PAUSE_PENDING);
pThis->m_state = OMX_StatePause;
pThis->m_pCallbacks.EventHandler(&pThis->m_cmp, pThis->m_app_data,
OMX_EventCmdComplete,OMX_CommandStateSet,
OMX_StatePause, NULL);
}
}
break;
case OMX_COMPONENT_GENERATE_RESUME_DONE:
DEBUG_PRINT_LOW("\n OMX_COMPONENT_GENERATE_RESUME_DONE msg");
if(pThis->m_pCallbacks.EventHandler)
{
if(BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_EXECUTE_PENDING))
{
// Send the callback now
BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_EXECUTE_PENDING);
pThis->m_state = OMX_StateExecuting;
pThis->m_pCallbacks.EventHandler(&pThis->m_cmp, pThis->m_app_data,
OMX_EventCmdComplete,OMX_CommandStateSet,
OMX_StateExecuting,NULL);
}
}
break;
case OMX_COMPONENT_GENERATE_STOP_DONE:
DEBUG_PRINT_LOW("\n OMX_COMPONENT_GENERATE_STOP_DONE msg");
if(pThis->m_pCallbacks.EventHandler)
{
pThis->complete_pending_buffer_done_cbs();
if(BITMASK_PRESENT(&pThis->m_flags,OMX_COMPONENT_IDLE_PENDING))
{
// Send the callback now
BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_IDLE_PENDING);
pThis->m_state = OMX_StateIdle;
pThis->m_pCallbacks.EventHandler(&pThis->m_cmp,pThis->m_app_data,
OMX_EventCmdComplete,OMX_CommandStateSet,
OMX_StateIdle,NULL);
}
else if (BITMASK_PRESENT(&pThis->m_flags,
OMX_COMPONENT_LOADED_STOP_PENDING))
{
if(dev_loaded_stop_done())
{
DEBUG_PRINT_LOW("successful loaded Stop Done!");
}
else
{
DEBUG_PRINT_ERROR("ERROR: failed in loaded Stop Done!");
pThis->omx_report_error ();
}
BITMASK_CLEAR((&pThis->m_flags),OMX_COMPONENT_LOADED_STOP_PENDING);
}
else
{
DEBUG_PRINT_ERROR("\nERROR: unknown flags=%x\n",pThis->m_flags);
}
}
break;
case OMX_COMPONENT_GENERATE_HARDWARE_ERROR:
DEBUG_PRINT_ERROR("\nERROR: OMX_COMPONENT_GENERATE_HARDWARE_ERROR!\n");
pThis->omx_report_error ();
break;
default:
DEBUG_PRINT_LOW("\n process_event_cb unknown msg id 0x%02x", id);
break;
}
}
pthread_mutex_lock(&pThis->m_lock);
qsize = pThis->m_cmd_q.m_size + pThis->m_ftb_q.m_size +\
pThis->m_etb_q.m_size;
pthread_mutex_unlock(&pThis->m_lock);
}
while(qsize>0);
DEBUG_PRINT_LOW("\n exited the while loop\n");
}
/* ======================================================================
FUNCTION
omx_venc::GetComponentVersion
DESCRIPTION
Returns the component version.
PARAMETERS
TBD.
RETURN VALUE
OMX_ErrorNone.
========================================================================== */
OMX_ERRORTYPE omx_video::get_component_version
(
OMX_IN OMX_HANDLETYPE hComp,
OMX_OUT OMX_STRING componentName,
OMX_OUT OMX_VERSIONTYPE* componentVersion,
OMX_OUT OMX_VERSIONTYPE* specVersion,
OMX_OUT OMX_UUIDTYPE* componentUUID
)
{
if(m_state == OMX_StateInvalid)
{
DEBUG_PRINT_ERROR("ERROR: Get Comp Version in Invalid State\n");
return OMX_ErrorInvalidState;
}
/* TBD -- Return the proper version */
if (specVersion)
{
specVersion->nVersion = OMX_SPEC_VERSION;
}
return OMX_ErrorNone;
}
/* ======================================================================
FUNCTION
omx_venc::SendCommand
DESCRIPTION
Returns zero if all the buffers released..
PARAMETERS
None.
RETURN VALUE
true/false
========================================================================== */
OMX_ERRORTYPE omx_video::send_command(OMX_IN OMX_HANDLETYPE hComp,
OMX_IN OMX_COMMANDTYPE cmd,
OMX_IN OMX_U32 param1,
OMX_IN OMX_PTR cmdData
)
{
if(m_state == OMX_StateInvalid)
{
DEBUG_PRINT_ERROR("ERROR: Send Command in Invalid State\n");
return OMX_ErrorInvalidState;
}
if(cmd == OMX_CommandFlush || cmd == OMX_CommandPortDisable || cmd == OMX_CommandPortEnable)
{
if((param1 != PORT_INDEX_IN) && (param1 != PORT_INDEX_OUT) && (param1 != PORT_INDEX_BOTH))
{
DEBUG_PRINT_ERROR("ERROR: omx_video::send_command-->bad port index\n");
return OMX_ErrorBadPortIndex;
}
}
if(cmd == OMX_CommandMarkBuffer)
{
if(param1 != PORT_INDEX_IN)
{
DEBUG_PRINT_ERROR("ERROR: omx_video::send_command-->bad port index \n");
return OMX_ErrorBadPortIndex;
}
if(!cmdData)
{
DEBUG_PRINT_ERROR("ERROR: omx_video::send_command-->param is null");
return OMX_ErrorBadParameter;
}
}
post_event((unsigned)cmd,(unsigned)param1,OMX_COMPONENT_GENERATE_COMMAND);
sem_wait(&m_cmd_lock);
return OMX_ErrorNone;
}
/* ======================================================================
FUNCTION
omx_venc::SendCommand
DESCRIPTION
Returns zero if all the buffers released..
PARAMETERS
None.
RETURN VALUE
true/false
========================================================================== */
OMX_ERRORTYPE omx_video::send_command_proxy(OMX_IN OMX_HANDLETYPE hComp,
OMX_IN OMX_COMMANDTYPE cmd,
OMX_IN OMX_U32 param1,
OMX_IN OMX_PTR cmdData
)
{
OMX_ERRORTYPE eRet = OMX_ErrorNone;
OMX_STATETYPE eState = (OMX_STATETYPE) param1;
int bFlag = 1;
if(cmd == OMX_CommandStateSet)
{
/***************************/
/* Current State is Loaded */
/***************************/
if(m_state == OMX_StateLoaded)
{
if(eState == OMX_StateIdle)
{
//if all buffers are allocated or all ports disabled
if(allocate_done() ||
( m_sInPortDef.bEnabled == OMX_FALSE && m_sOutPortDef.bEnabled == OMX_FALSE))
{
DEBUG_PRINT_LOW("OMXCORE-SM: Loaded-->Idle\n");
}
else
{
DEBUG_PRINT_LOW("OMXCORE-SM: Loaded-->Idle-Pending\n");
BITMASK_SET(&m_flags, OMX_COMPONENT_IDLE_PENDING);
// Skip the event notification
bFlag = 0;
}
}
/* Requesting transition from Loaded to Loaded */
else if(eState == OMX_StateLoaded)
{
DEBUG_PRINT_ERROR("ERROR: OMXCORE-SM: Loaded-->Loaded\n");
post_event(OMX_EventError,OMX_ErrorSameState,\
OMX_COMPONENT_GENERATE_EVENT);
eRet = OMX_ErrorSameState;
}
/* Requesting transition from Loaded to WaitForResources */
else if(eState == OMX_StateWaitForResources)
{
/* Since error is None , we will post an event
at the end of this function definition */
DEBUG_PRINT_LOW("OMXCORE-SM: Loaded-->WaitForResources\n");
}
/* Requesting transition from Loaded to Executing */
else if(eState == OMX_StateExecuting)
{
DEBUG_PRINT_ERROR("ERROR: OMXCORE-SM: Loaded-->Executing\n");
post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
OMX_COMPONENT_GENERATE_EVENT);
eRet = OMX_ErrorIncorrectStateTransition;
}
/* Requesting transition from Loaded to Pause */
else if(eState == OMX_StatePause)
{
DEBUG_PRINT_ERROR("ERROR: OMXCORE-SM: Loaded-->Pause\n");
post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
OMX_COMPONENT_GENERATE_EVENT);
eRet = OMX_ErrorIncorrectStateTransition;
}
/* Requesting transition from Loaded to Invalid */
else if(eState == OMX_StateInvalid)
{
DEBUG_PRINT_ERROR("ERROR: OMXCORE-SM: Loaded-->Invalid\n");
post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
eRet = OMX_ErrorInvalidState;
}
else
{
DEBUG_PRINT_ERROR("ERROR: OMXCORE-SM: Loaded-->%d Not Handled\n",\
eState);
eRet = OMX_ErrorBadParameter;
}
}
/***************************/
/* Current State is IDLE */
/***************************/
else if(m_state == OMX_StateIdle)
{
if(eState == OMX_StateLoaded)
{
if(release_done())
{
/*
Since error is None , we will post an event at the end
of this function definition
*/
DEBUG_PRINT_LOW("OMXCORE-SM: Idle-->Loaded\n");
if(dev_stop() != 0)
{
DEBUG_PRINT_ERROR("\nERROR: dev_stop() failed at Idle --> Loaded");
eRet = OMX_ErrorHardware;
}
}
else
{
DEBUG_PRINT_LOW("OMXCORE-SM: Idle-->Loaded-Pending\n");
BITMASK_SET(&m_flags, OMX_COMPONENT_LOADING_PENDING);
// Skip the event notification
bFlag = 0;
}
}
/* Requesting transition from Idle to Executing */
else if(eState == OMX_StateExecuting)
{
if( dev_start() )
{
DEBUG_PRINT_ERROR("\nERROR: dev_start() failed in SCP on Idle --> Exe\n");
omx_report_error ();
eRet = OMX_ErrorHardware;
}
else
{
BITMASK_SET(&m_flags,OMX_COMPONENT_EXECUTE_PENDING);
DEBUG_PRINT_LOW("OMXCORE-SM: Idle-->Executing\n");
bFlag = 0;
}
dev_start_done();
}
/* Requesting transition from Idle to Idle */
else if(eState == OMX_StateIdle)
{
DEBUG_PRINT_ERROR("ERROR: OMXCORE-SM: Idle-->Idle\n");
post_event(OMX_EventError,OMX_ErrorSameState,\
OMX_COMPONENT_GENERATE_EVENT);
eRet = OMX_ErrorSameState;
}
/* Requesting transition from Idle to WaitForResources */
else if(eState == OMX_StateWaitForResources)
{
DEBUG_PRINT_ERROR("ERROR: OMXCORE-SM: Idle-->WaitForResources\n");
post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
OMX_COMPONENT_GENERATE_EVENT);
eRet = OMX_ErrorIncorrectStateTransition;
}
/* Requesting transition from Idle to Pause */
else if(eState == OMX_StatePause)
{
/*To pause the Video core we need to start the driver*/
if( dev_start() )
{
DEBUG_PRINT_ERROR("\nERROR: dev_start() failed in SCP on Idle --> Pause\n");
omx_report_error ();
eRet = OMX_ErrorHardware;
}
else
{
BITMASK_SET(&m_flags,OMX_COMPONENT_PAUSE_PENDING);
DEBUG_PRINT_LOW("OMXCORE-SM: Idle-->Pause\n");
bFlag = 0;
}
}
/* Requesting transition from Idle to Invalid */
else if(eState == OMX_StateInvalid)
{
DEBUG_PRINT_ERROR("ERROR: OMXCORE-SM: Idle-->Invalid\n");
post_event(OMX_EventError,eState,OMX_COMPONENT_GENERATE_EVENT);
eRet = OMX_ErrorInvalidState;
}
else
{
DEBUG_PRINT_ERROR("ERROR: OMXCORE-SM: Idle --> %d Not Handled\n",eState);
eRet = OMX_ErrorBadParameter;
}
}
/******************************/
/* Current State is Executing */
/******************************/
else if(m_state == OMX_StateExecuting)
{
/* Requesting transition from Executing to Idle */
if(eState == OMX_StateIdle)
{
/* Since error is None , we will post an event
at the end of this function definition
*/
DEBUG_PRINT_LOW("\n OMXCORE-SM: Executing --> Idle \n");
//here this should be Pause-Idle pending and should be cleared when flush is complete and change the state to Idle
BITMASK_SET(&m_flags,OMX_COMPONENT_IDLE_PENDING);
execute_omx_flush(OMX_ALL);
bFlag = 0;
dev_stop_done();
}
/* Requesting transition from Executing to Paused */
else if(eState == OMX_StatePause)
{
if(dev_pause())
{
DEBUG_PRINT_ERROR("\nERROR: dev_pause() failed in SCP on Exe --> Pause\n");
post_event(OMX_EventError,OMX_ErrorHardware,\
OMX_COMPONENT_GENERATE_EVENT);
eRet = OMX_ErrorHardware;
}
else
{
BITMASK_SET(&m_flags,OMX_COMPONENT_PAUSE_PENDING);
DEBUG_PRINT_LOW("OMXCORE-SM: Executing-->Pause\n");
bFlag = 0;
}
}
/* Requesting transition from Executing to Loaded */
else if(eState == OMX_StateLoaded)
{
DEBUG_PRINT_ERROR("\nERROR: OMXCORE-SM: Executing --> Loaded \n");
post_event(OMX_EventError,OMX_ErrorIncorrectStateTransition,\
OMX_COMPONENT_GENERATE_EVENT);