-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
kodi-999.16-amlogic_timing.patch
4262 lines (3866 loc) · 148 KB
/
kodi-999.16-amlogic_timing.patch
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
From f35b302861b90fb25acad6ea3430e95a58ac394e Mon Sep 17 00:00:00 2001
From: Markus Pfau <pfau@peak3d.de>
Date: Fri, 18 Nov 2016 14:39:30 +0100
Subject: [PATCH 01/30] sync kodi clock to AML clock
---
.../cores/VideoPlayer/DVDCodecs/Video/AMLCodec.cpp | 219 +++++++++++----------
xbmc/cores/VideoPlayer/DVDCodecs/Video/AMLCodec.h | 26 ++-
.../DVDCodecs/Video/DVDVideoCodecAmlogic.cpp | 34 ++--
.../DVDCodecs/Video/DVDVideoCodecAmlogic.h | 5 +-
.../VideoRenderers/HwDecRender/RendererAML.cpp | 137 ++++++++++---
.../VideoRenderers/HwDecRender/RendererAML.h | 36 +++-
6 files changed, 286 insertions(+), 171 deletions(-)
diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/AMLCodec.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Video/AMLCodec.cpp
index c38c223..0ab8567 100644
--- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/AMLCodec.cpp
+++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/AMLCodec.cpp
@@ -26,6 +26,7 @@
#include "cores/VideoPlayer/DVDClock.h"
#include "cores/VideoPlayer/VideoRenderers/RenderFlags.h"
#include "cores/VideoPlayer/VideoRenderers/RenderManager.h"
+#include "settings/AdvancedSettings.h"
#include "guilib/GraphicContext.h"
#include "settings/DisplaySettings.h"
#include "settings/MediaSettings.h"
@@ -49,11 +50,11 @@ extern "C" {
#include <queue>
#include <vector>
#include <signal.h>
-#include <semaphore.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
+#include <sys/utsname.h>
#include <linux/videodev2.h>
// amcodec include
@@ -133,6 +134,11 @@ class DllLibamCodecInterface
virtual int codec_set_cntl_mode(codec_para_t *pcodec, unsigned int mode)=0;
virtual int codec_set_cntl_avthresh(codec_para_t *pcodec, unsigned int avthresh)=0;
virtual int codec_set_cntl_syncthresh(codec_para_t *pcodec, unsigned int syncthresh)=0;
+
+ virtual int codec_set_av_threshold(codec_para_t *pcodec, int threshold)=0;
+ virtual int codec_set_video_delay_limited_ms(codec_para_t *pcodec,int delay_ms)=0;
+ virtual int codec_get_video_delay_limited_ms(codec_para_t *pcodec,int *delay_ms)=0;
+ virtual int codec_get_video_cur_delay_ms(codec_para_t *pcodec,int *delay_ms)=0;
};
class DllLibAmCodec : public DllDynamic, DllLibamCodecInterface
@@ -156,6 +162,11 @@ class DllLibAmCodec : public DllDynamic, DllLibamCodecInterface
DEFINE_METHOD2(int, codec_set_cntl_avthresh, (codec_para_t *p1, unsigned int p2))
DEFINE_METHOD2(int, codec_set_cntl_syncthresh,(codec_para_t *p1, unsigned int p2))
+ DEFINE_METHOD2(int, codec_set_av_threshold, (codec_para_t *p1, int p2))
+ DEFINE_METHOD2(int, codec_set_video_delay_limited_ms, (codec_para_t *p1, int p2))
+ DEFINE_METHOD2(int, codec_get_video_delay_limited_ms, (codec_para_t *p1, int *p2))
+ DEFINE_METHOD2(int, codec_get_video_cur_delay_ms, (codec_para_t *p1, int *p2))
+
BEGIN_METHOD_RESOLVE()
RESOLVE_METHOD(codec_init)
RESOLVE_METHOD(codec_close)
@@ -172,6 +183,11 @@ class DllLibAmCodec : public DllDynamic, DllLibamCodecInterface
RESOLVE_METHOD(codec_set_cntl_mode)
RESOLVE_METHOD(codec_set_cntl_avthresh)
RESOLVE_METHOD(codec_set_cntl_syncthresh)
+
+ RESOLVE_METHOD(codec_set_av_threshold)
+ RESOLVE_METHOD(codec_set_video_delay_limited_ms)
+ RESOLVE_METHOD(codec_get_video_delay_limited_ms)
+ RESOLVE_METHOD(codec_get_video_cur_delay_ms)
END_METHOD_RESOLVE()
public:
@@ -273,7 +289,7 @@ class DllLibAmCodec : public DllDynamic, DllLibamCodecInterface
#define PTS_FREQ 90000
#define UNIT_FREQ 96000
-#define AV_SYNC_THRESH PTS_FREQ*30
+#define AV_SYNC_THRESH PTS_FREQ*0
#define TRICKMODE_NONE 0x00
#define TRICKMODE_I 0x01
@@ -371,6 +387,18 @@ typedef struct am_private_t
bool dumpdemux;
} am_private_t;
+typedef struct vframe_states
+{
+ int vf_pool_size;
+ int buf_free_num;
+ int buf_recycle_num;
+ int buf_avail_num;
+} vframe_states_t;
+
+#define AMSTREAM_IOC_MAGIC 'S'
+#define AMSTREAM_IOC_VF_STATUS _IOR(AMSTREAM_IOC_MAGIC, 0x60, unsigned long)
+
+
/*************************************************************************/
/*************************************************************************/
void dumpfile_open(am_private_t *para)
@@ -713,7 +741,7 @@ int write_av_packet(am_private_t *para, am_packet_t *pkt)
}
pkt->newflag = 0;
}
-
+
buf = pkt->data;
size = pkt->data_size ;
if (size == 0 && pkt->isvalid) {
@@ -1380,9 +1408,12 @@ int set_header_info(am_private_t *para)
/*************************************************************************/
CAMLCodec::CAMLCodec()
- : CThread("CAMLCodec")
+ : m_prefill_state(PREFILL_STATE_FILLING)
+ , m_opened(false)
+ , m_ptsIs64us(false)
+ , m_last_pts(0)
+ , m_cur_pts(0)
{
- m_opened = false;
am_private = new am_private_t;
memset(am_private, 0, sizeof(am_private_t));
m_dll = new DllLibAmCodec;
@@ -1402,12 +1433,26 @@ CAMLCodec::CAMLCodec()
CAMLCodec::~CAMLCodec()
{
- StopThread();
delete am_private;
am_private = NULL;
delete m_dll, m_dll = NULL;
}
+float CAMLCodec::OMXPtsToSeconds(int omxpts)
+{
+ return static_cast<float>(omxpts) / PTS_FREQ;
+}
+
+int CAMLCodec::OMXDurationToNs(int duration)
+{
+ return static_cast<int>(static_cast<float>(duration) / PTS_FREQ * 1000000 );
+}
+
+int CAMLCodec::GetAmlDuration() const
+{
+ return am_private ? (am_private->video_rate * PTS_FREQ) / UNIT_FREQ : 0;
+};
+
bool CAMLCodec::OpenDecoder(CDVDStreamInfo &hints)
{
#ifdef TARGET_ANDROID
@@ -1415,7 +1460,6 @@ bool CAMLCodec::OpenDecoder(CDVDStreamInfo &hints)
#endif
m_speed = DVD_PLAYSPEED_NORMAL;
- m_1st_pts = 0;
m_cur_pts = 0;
m_dst_rect.SetRect(0, 0, 0, 0);
m_zoom = -1;
@@ -1615,9 +1659,10 @@ bool CAMLCodec::OpenDecoder(CDVDStreamInfo &hints)
am_private->dumpdemux = false;
dumpfile_open(am_private);
- //! @bug make sure we are not stuck in pause (amcodec bug)
m_dll->codec_resume(&am_private->vcodec);
+
m_dll->codec_set_cntl_mode(&am_private->vcodec, TRICKMODE_NONE);
+ m_dll->codec_set_video_delay_limited_ms(&am_private->vcodec, 1000);
m_dll->codec_set_cntl_avthresh(&am_private->vcodec, AV_SYNC_THRESH);
m_dll->codec_set_cntl_syncthresh(&am_private->vcodec, 0);
@@ -1627,8 +1672,6 @@ bool CAMLCodec::OpenDecoder(CDVDStreamInfo &hints)
am_private->am_pkt.codec = &am_private->vcodec;
pre_header_feeding(am_private, &am_private->am_pkt);
- Create();
-
m_display_rect = CRect(0, 0, CDisplaySettings::GetInstance().GetCurrentResolutionInfo().iWidth, CDisplaySettings::GetInstance().GetCurrentResolutionInfo().iHeight);
std::string strScaler;
@@ -1636,16 +1679,19 @@ bool CAMLCodec::OpenDecoder(CDVDStreamInfo &hints)
if (strScaler.find("enabled") == std::string::npos) // Scaler not enabled, use screen size
m_display_rect = CRect(0, 0, CDisplaySettings::GetInstance().GetCurrentResolutionInfo().iScreenWidth, CDisplaySettings::GetInstance().GetCurrentResolutionInfo().iScreenHeight);
-/*
- // if display is set to 1080xxx, then disable deinterlacer for HD content
- // else bandwidth usage is too heavy and it will slow down video decoder.
- char display_mode[256] = {0};
- SysfsUtils::GetString("/sys/class/display/mode", display_mode, 255);
- if (strstr(display_mode,"1080"))
- SysfsUtils::SetInt("/sys/module/di/parameters/bypass_all", 1);
- else
- SysfsUtils::SetInt("/sys/module/di/parameters/bypass_all", 0);
-*/
+ SysfsUtils::SetInt("/sys/class/video/freerun_mode", 0);
+
+
+ struct utsname un;
+ if (uname(&un) == 0)
+ {
+ int linuxversion[2];
+ sscanf(un.release,"%d.%d", &linuxversion[0], &linuxversion[1]);
+ if (linuxversion[0] > 3 || (linuxversion[0] == 3 && linuxversion[1] >= 14))
+ m_ptsIs64us = true;
+ }
+
+ CLog::Log(LOGNOTICE, "CAMLCodec::OpenDecoder - using V4L2 pts format: %s", m_ptsIs64us ? "64Bit":"32Bit");
m_opened = true;
// vcodec is open, update speed if it was
@@ -1705,7 +1751,6 @@ void CAMLCodec::SetVfmMap(const std::string &name, const std::string &map)
void CAMLCodec::CloseDecoder()
{
CLog::Log(LOGDEBUG, "CAMLCodec::CloseDecoder");
- StopThread();
// never leave vcodec ff/rw or paused.
if (m_speed != DVD_PLAYSPEED_NORMAL)
@@ -1754,6 +1799,8 @@ void CAMLCodec::Reset()
}
// reset the decoder
m_dll->codec_reset(&am_private->vcodec);
+ m_dll->codec_set_video_delay_limited_ms(&am_private->vcodec, 1000);
+
dumpfile_close(am_private);
dumpfile_open(am_private);
@@ -1767,9 +1814,8 @@ void CAMLCodec::Reset()
SysfsUtils::SetInt("/sys/class/video/blackout_policy", blackout_policy);
// reset some interal vars
- m_1st_pts = 0;
m_cur_pts = 0;
- m_ptsQueue.clear();
+ m_prefill_state = PREFILL_STATE_FILLING;
SetSpeed(m_speed);
}
@@ -1778,6 +1824,7 @@ int CAMLCodec::Decode(uint8_t *pData, size_t iSize, double dts, double pts)
if (!m_opened)
return VC_BUFFER;
+ float timesize(static_cast<float>(GetTimeSize()));
if (pData)
{
am_private->am_pkt.data = pData;
@@ -1813,9 +1860,6 @@ int CAMLCodec::Decode(uint8_t *pData, size_t iSize, double dts, double pts)
if (am_private->am_pkt.avdts != (int64_t)AV_NOPTS_VALUE)
am_private->am_pkt.avdts -= m_start_dts;
- //CLog::Log(LOGDEBUG, "CAMLCodec::Decode: iSize(%d), dts(%f), pts(%f), avdts(%llx), avpts(%llx)",
- // iSize, dts, pts, am_private->am_pkt.avdts, am_private->am_pkt.avpts);
-
// some formats need header/data tweaks.
// the actual write occurs once in write_av_packet
// and is controlled by am_pkt.newflag.
@@ -1840,47 +1884,39 @@ int CAMLCodec::Decode(uint8_t *pData, size_t iSize, double dts, double pts)
// Decoder got stuck; Reset
Reset();
}
-
- // if we seek, then GetTimeSize is wrong as
- // reports lastpts - cur_pts and hw decoder has
- // not started outputing new pts values yet.
- // so we grab the 1st pts sent into driver and
- // use that to calc GetTimeSize.
- if (m_1st_pts == 0)
- m_1st_pts = am_private->am_pkt.lastpts;
+ if (m_prefill_state == PREFILL_STATE_FILLING && timesize >= 1.0)
+ m_prefill_state = PREFILL_STATE_FILLED;
}
- // if we have still frames, demux size will be small
- // and we need to pre-buffer more.
- double target_timesize = 1.0;
- if (iSize < 20)
- target_timesize = 2.0;
-
- int rtn = 0;
-
- // keep hw buffered demux above 1 second
- if (GetTimeSize() < target_timesize)
- rtn |= VC_BUFFER;
-
- // wait until we get a new frame or 25ms,
- if (m_ptsQueue.size() == 0)
- m_ready_event.WaitMSec(25);
-
- if (m_ptsQueue.size() > 0)
+ int rtn(0);
+ int64_t decode_pts = 0;
+ if (m_prefill_state == PREFILL_STATE_FILLED && timesize > 0.5 && DequeueBuffer(decode_pts) == 0)
{
- CSingleLock lock(m_ptsQueueMutex);
- m_cur_pts = m_ptsQueue.front();
- m_ptsQueue.pop_front();
rtn |= VC_PICTURE;
+ m_last_pts = m_cur_pts;
+ m_cur_pts = decode_pts;
}
-/*
- CLog::Log(LOGDEBUG, "CAMLCodec::Decode: "
- "rtn(%d), m_cur_pictcnt(%lld), m_cur_pts(%f), lastpts(%f), GetTimeSize(%f), GetDataSize(%d)",
- rtn, m_cur_pictcnt, (float)m_cur_pts/PTS_FREQ, (float)am_private->am_pkt.lastpts/PTS_FREQ, GetTimeSize(), GetDataSize());
-*/
+ if ((rtn & VC_PICTURE)==0 || timesize < 1.0)
+ rtn |= VC_BUFFER;
+
+ if (g_advancedSettings.CanLogComponent(LOGVIDEO))
+ CLog::Log(LOGDEBUG, "CAMLCodec::Decode: ret: %d dts_in: %0.6f, pts_in: %0.6f, ptsOut:%0.6f, amlpts:%d timesize:%0.2f",
+ rtn,
+ static_cast<float>(dts)/DVD_TIME_BASE,
+ static_cast<float>(pts)/DVD_TIME_BASE,
+ static_cast<float>(m_cur_pts)/PTS_FREQ,
+ static_cast<int>(m_cur_pts),
+ timesize
+ );
+
return rtn;
}
+int CAMLCodec::PollFrame()
+{
+ return m_dll->codec_poll_cntl(&am_private->vcodec);
+}
+
int CAMLCodec::DequeueBuffer(int64_t &pts)
{
v4l2_buffer vbuf = { 0 };
@@ -1896,7 +1932,7 @@ int CAMLCodec::DequeueBuffer(int64_t &pts)
// Since kernel 3.14 Amlogic changed length and units of PTS values reported here.
// To differentiate such PTS values we check for existence of omx_pts_interval_lower
// parameter, because it was introduced since kernel 3.14.
- if (access("/sys/module/amvideo/parameters/omx_pts_interval_lower", F_OK) != -1)
+ if (m_ptsIs64us)
{
pts = vbuf.timestamp.tv_sec & 0xFFFFFFFF;
pts <<= 32;
@@ -1917,18 +1953,17 @@ bool CAMLCodec::GetPicture(DVDVideoPicture *pDvdVideoPicture)
pDvdVideoPicture->iFlags = DVP_FLAG_ALLOCATED;
pDvdVideoPicture->format = RENDER_FMT_AML;
- pDvdVideoPicture->iDuration = (double)(am_private->video_rate * DVD_TIME_BASE) / UNIT_FREQ;
- pDvdVideoPicture->dts = DVD_NOPTS_VALUE;
- if (m_speed == DVD_PLAYSPEED_NORMAL)
- pDvdVideoPicture->pts = (double)m_cur_pts / PTS_FREQ * DVD_TIME_BASE;
+ if (m_last_pts <= 0)
+ pDvdVideoPicture->iDuration = (double)(am_private->video_rate * DVD_TIME_BASE) / UNIT_FREQ;
else
- {
- if (m_cur_pts == 0)
- pDvdVideoPicture->pts = (double)m_1st_pts / PTS_FREQ * DVD_TIME_BASE;
- else
- pDvdVideoPicture->pts = (double)m_cur_pts / PTS_FREQ * DVD_TIME_BASE;
- }
+ pDvdVideoPicture->iDuration = (double)((m_cur_pts - m_last_pts) * DVD_TIME_BASE) / PTS_FREQ;
+
+ pDvdVideoPicture->dts = DVD_NOPTS_VALUE;
+ pDvdVideoPicture->pts = (double)m_cur_pts / PTS_FREQ * DVD_TIME_BASE;
+
+ //AML video is ~ 2 frames to fast - sync audio
+ pDvdVideoPicture->pts += 2*pDvdVideoPicture->iDuration;
return true;
}
@@ -1981,17 +2016,13 @@ double CAMLCodec::GetTimeSize()
if (!m_opened)
return 0;
- // if m_cur_pts is zero, hw decoder was not started yet
- // so we use the pts of the 1st demux packet that was send
- // to hw decoder to calc timesize.
- if (m_cur_pts == 0)
- m_timesize = (double)(am_private->am_pkt.lastpts - m_1st_pts) / PTS_FREQ;
- else
- m_timesize = (double)(am_private->am_pkt.lastpts - GetOMXPts()) / PTS_FREQ;
+ int video_delay_ms;
+ double timesize(0);
+ if (m_dll->codec_get_video_cur_delay_ms(&am_private->vcodec, &video_delay_ms) >= 0)
+ timesize = (float)video_delay_ms / 1000.0;
// lie to VideoPlayer, it is hardcoded to a max of 8 seconds,
// if you buffer more than 8 seconds, it goes nuts.
- double timesize = m_timesize;
if (timesize < 0.0)
timesize = 0.0;
else if (timesize > 7.0)
@@ -2000,32 +2031,6 @@ double CAMLCodec::GetTimeSize()
return timesize;
}
-void CAMLCodec::Process()
-{
- CLog::Log(LOGDEBUG, "CAMLCodec::Process Started");
-
- while (!m_bStop)
- {
- if (m_dll->codec_poll_cntl(&am_private->vcodec) < 0)
- {
- CLog::Log(LOGDEBUG, "CAMLCodec::Process: codec_poll_cntl failed");
- Sleep(10);
- }
-
- {
- CSingleLock lock(m_ptsQueueMutex);
- int64_t pts = 0;
- if (DequeueBuffer(pts) == 0)
- {
- m_ptsQueue.push_back(pts + m_start_pts);
- m_ready_event.Set();
- }
- }
- }
-
- CLog::Log(LOGDEBUG, "CAMLCodec::Process Stopped");
-}
-
void CAMLCodec::ShowMainVideo(const bool show)
{
static int saved_disable_video = -1;
@@ -2273,3 +2278,9 @@ void CAMLCodec::SetVideoRect(const CRect &SrcRect, const CRect &DestRect)
// that would show video playback, so show it.
ShowMainVideo(true);
}
+
+void CAMLCodec::SetVideoRate(int videoRate)
+{
+ if (am_private)
+ am_private->video_rate = videoRate;
+}
diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/AMLCodec.h b/xbmc/cores/VideoPlayer/DVDCodecs/Video/AMLCodec.h
index 0eb5c3e..33fa0b7 100644
--- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/AMLCodec.h
+++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/AMLCodec.h
@@ -24,8 +24,6 @@
#include "cores/IPlayer.h"
#include "guilib/Geometry.h"
#include "rendering/RenderSystem.h"
-#include "threads/Thread.h"
-#include <deque>
typedef struct am_private_t am_private_t;
@@ -34,7 +32,7 @@ class DllLibAmCodec;
class PosixFile;
typedef std::shared_ptr<PosixFile> PosixFilePtr;
-class CAMLCodec : public CThread
+class CAMLCodec
{
public:
CAMLCodec();
@@ -51,11 +49,13 @@ class CAMLCodec : public CThread
int GetDataSize();
double GetTimeSize();
void SetVideoRect(const CRect &SrcRect, const CRect &DestRect);
+ void SetVideoRate(int videoRate);
int64_t GetCurPts() const { return m_cur_pts; }
int GetOMXPts() const { return static_cast<int>(m_cur_pts - m_start_pts); }
-
-protected:
- virtual void Process();
+ static float OMXPtsToSeconds(int omxpts);
+ static int OMXDurationToNs(int duration);
+ int GetAmlDuration() const;
+ int PollFrame();
private:
void ShowMainVideo(const bool show);
@@ -73,16 +73,15 @@ class CAMLCodec : public CThread
DllLibAmCodec *m_dll;
bool m_opened;
+ bool m_ptsIs64us;
am_private_t *am_private;
CDVDStreamInfo m_hints;
volatile int m_speed;
- volatile int64_t m_1st_pts;
volatile int64_t m_cur_pts;
- volatile double m_timesize;
volatile int64_t m_vbufsize;
int64_t m_start_dts;
int64_t m_start_pts;
- CEvent m_ready_event;
+ int64_t m_last_pts;
CRect m_dst_rect;
CRect m_display_rect;
@@ -94,8 +93,15 @@ class CAMLCodec : public CThread
int m_contrast;
int m_brightness;
+ enum PREFILLSTATE
+ {
+ PREFILL_STATE_FILLING,
+ PREFILL_STATE_FILLED
+ };
+ PREFILLSTATE m_prefill_state;
+
+
PosixFilePtr m_amlVideoFile;
std::string m_defaultVfmMap;
- std::deque<int64_t> m_ptsQueue;
CCriticalSection m_ptsQueueMutex;
};
diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAmlogic.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAmlogic.cpp
index a27d3e3..a0f847a 100644
--- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAmlogic.cpp
+++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAmlogic.cpp
@@ -30,6 +30,7 @@
#include "utils/SysfsUtils.h"
#include "threads/Atomics.h"
#include "settings/Settings.h"
+#include "threads/Thread.h"
#define __MODULE_NAME__ "DVDVideoCodecAmlogic"
@@ -236,6 +237,7 @@ bool CDVDVideoCodecAmlogic::Open(CDVDStreamInfo &hints, CDVDCodecOptions &option
m_processInfo.SetVideoDecoderName(m_pFormatName, true);
m_processInfo.SetVideoDimensions(m_hints.width, m_hints.height);
m_processInfo.SetVideoDeintMethod("hardware");
+ m_processInfo.SetVideoDAR(m_hints.aspect);
CLog::Log(LOGINFO, "%s: Opened Amlogic Codec", __MODULE_NAME__);
return true;
@@ -315,7 +317,7 @@ bool CDVDVideoCodecAmlogic::GetPicture(DVDVideoPicture* pDvdVideoPicture)
m_Codec->GetPicture(&m_videobuffer);
*pDvdVideoPicture = m_videobuffer;
- CDVDAmlogicInfo* info = new CDVDAmlogicInfo(this, m_Codec, m_Codec->GetOMXPts());
+ CDVDAmlogicInfo* info = new CDVDAmlogicInfo(this, m_Codec, m_Codec->GetOMXPts(), m_Codec->GetAmlDuration());
{
CSingleLock lock(m_secure);
@@ -363,7 +365,7 @@ void CDVDVideoCodecAmlogic::SetDropState(bool bDrop)
// Freerun mode causes amvideo driver to ignore timing and process frames
// as quickly as they are coming from decoder. By enabling freerun mode we can
// skip rendering of the frames that are requested to be dropped by VideoPlayer.
- SysfsUtils::SetInt("/sys/class/video/freerun_mode", bDrop ? 1 : 0);
+ //SysfsUtils::SetInt("/sys/class/video/freerun_mode", bDrop ? 1 : 0);
}
void CDVDVideoCodecAmlogic::SetSpeed(int iSpeed)
@@ -466,8 +468,7 @@ void CDVDVideoCodecAmlogic::FrameRateTracking(uint8_t *pData, int iSize, double
m_framerate = m_mpeg2_sequence->rate;
m_video_rate = (int)(0.5 + (96000.0 / m_framerate));
- CLog::Log(LOGDEBUG, "%s: detected mpeg2 aspect ratio(%f), framerate(%f), video_rate(%d)",
- __MODULE_NAME__, m_mpeg2_sequence->ratio, m_framerate, m_video_rate);
+ m_processInfo.SetVideoFps(m_framerate);
// update m_hints for 1st frame fixup.
switch(m_mpeg2_sequence->rate_info)
@@ -526,7 +527,7 @@ void CDVDVideoCodecAmlogic::FrameRateTracking(uint8_t *pData, int iSize, double
if (cur_pts == DVD_NOPTS_VALUE)
cur_pts = m_frame_queue->dts;
- pthread_mutex_unlock(&m_queue_mutex);
+ pthread_mutex_unlock(&m_queue_mutex);
float duration = cur_pts - m_last_pts;
m_last_pts = cur_pts;
@@ -559,22 +560,10 @@ void CDVDVideoCodecAmlogic::FrameRateTracking(uint8_t *pData, int iSize, double
break;
// 25.000 (40000.000000)
- case 40000:
+ case 39900 ... 40100:
framerate = 25000.0 / 1000.0;
break;
- // 24.975 (40040.000000)
- case 40040:
- framerate = 25000.0 / 1001.0;
- break;
-
- /*
- // 24.000 (41666.666666)
- case 41667:
- framerate = 24000.0 / 1000.0;
- break;
- */
-
// 23.976 (41708.33333)
case 40200 ... 43200:
// 23.976 seems to have the crappiest encodings :)
@@ -592,6 +581,12 @@ void CDVDVideoCodecAmlogic::FrameRateTracking(uint8_t *pData, int iSize, double
{
m_framerate = framerate;
m_video_rate = (int)(0.5 + (96000.0 / framerate));
+
+ if (m_Codec)
+ m_Codec->SetVideoRate(m_video_rate);
+
+ m_processInfo.SetVideoFps(m_framerate);
+
CLog::Log(LOGDEBUG, "%s: detected new framerate(%f), video_rate(%d)",
__MODULE_NAME__, m_framerate, m_video_rate);
}
@@ -607,11 +602,12 @@ void CDVDVideoCodecAmlogic::RemoveInfo(CDVDAmlogicInfo *info)
m_inflight.erase(m_inflight.find(info));
}
-CDVDAmlogicInfo::CDVDAmlogicInfo(CDVDVideoCodecAmlogic *codec, CAMLCodec *amlcodec, int omxPts)
+CDVDAmlogicInfo::CDVDAmlogicInfo(CDVDVideoCodecAmlogic *codec, CAMLCodec *amlcodec, int omxPts, int amlDuration)
: m_refs(0)
, m_codec(codec)
, m_amlCodec(amlcodec)
, m_omxPts(omxPts)
+ , m_amlDuration(amlDuration)
{
}
diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAmlogic.h b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAmlogic.h
index 2c44241..39f408e 100644
--- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAmlogic.h
+++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAmlogic.h
@@ -36,7 +36,7 @@ class CDVDVideoCodecAmlogic;
class CDVDAmlogicInfo
{
public:
- CDVDAmlogicInfo(CDVDVideoCodecAmlogic *codec, CAMLCodec *amlcodec, int omxPts);
+ CDVDAmlogicInfo(CDVDVideoCodecAmlogic *codec, CAMLCodec *amlcodec, int omxPts, int amlDuration);
// reference counting
CDVDAmlogicInfo* Retain();
@@ -44,6 +44,7 @@ class CDVDAmlogicInfo
CAMLCodec *getAmlCodec() const;
int GetOmxPts() const { return m_omxPts; }
+ int GetAmlDuration() const { return m_amlDuration; }
void invalidate();
protected:
@@ -52,7 +53,7 @@ class CDVDAmlogicInfo
CDVDVideoCodecAmlogic* m_codec;
CAMLCodec* m_amlCodec;
- int m_omxPts;
+ int m_omxPts, m_amlDuration;
};
class CDVDVideoCodecAmlogic : public CDVDVideoCodec
diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/RendererAML.cpp b/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/RendererAML.cpp
index d8674c8..c45e94f 100644
--- a/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/RendererAML.cpp
+++ b/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/RendererAML.cpp
@@ -21,26 +21,84 @@
#include "RendererAML.h"
#if defined(HAS_LIBAMCODEC)
-#include "cores/IPlayer.h"
-#include "windowing/egl/EGLWrapper.h"
#include "cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAmlogic.h"
#include "cores/VideoPlayer/DVDCodecs/Video/AMLCodec.h"
#include "utils/log.h"
-#include "utils/GLUtils.h"
#include "utils/SysfsUtils.h"
#include "settings/MediaSettings.h"
#include "windowing/WindowingFactory.h"
#include "cores/VideoPlayer/VideoRenderers/RenderCapture.h"
+#include "settings/AdvancedSettings.h"
+
+static int get_pts(const char *strPath)
+{
+ int fd = open(strPath, O_RDONLY);
+ if (fd >= 0)
+ {
+ char pts_str[64];
+ int size = read(fd, pts_str, sizeof(pts_str));
+ close(fd);
+ return strtol(pts_str, NULL, 16);
+ }
+ return 0;
+}
+
+static void set_pts(const char *strPath, int pts)
+{
+ int fd = open(strPath, O_WRONLY);
+ if (fd >= 0)
+ {
+ char pts_str[64];
+ sprintf(pts_str, "0x%x", pts);
+ write(fd, pts_str, strlen(pts_str));
+ close(fd);
+ }
+}
CRendererAML::CRendererAML()
+ : m_prevPts(-1)
+ , m_bConfigured(false)
+ , m_iRenderBuffer(0)
+ , m_diff_counter(0)
{
- m_prevPts = -1;
}
CRendererAML::~CRendererAML()
{
}
+bool CRendererAML::Configure(unsigned int width, unsigned int height, unsigned int d_width, unsigned int d_height, float fps, unsigned flags, ERenderFormat format, unsigned extended_formatl, unsigned int orientation)
+{
+ m_sourceWidth = width;
+ m_sourceHeight = height;
+ m_renderOrientation = orientation;
+
+ // Save the flags.
+ m_iFlags = flags;
+ m_format = format;
+
+ // Calculate the input frame aspect ratio.
+ CalculateFrameAspectRatio(d_width, d_height);
+ SetViewMode(CMediaSettings::GetInstance().GetCurrentVideoSettings().m_ViewMode);
+ ManageRenderArea();
+
+ m_bConfigured = true;
+
+ for (int i = 0 ; i < m_numRenderBuffers ; ++i)
+ m_buffers[i].hwDec = 0;
+
+ return true;
+}
+
+CRenderInfo CRendererAML::GetRenderInfo()
+{
+ CRenderInfo info;
+ info.formats.push_back(RENDER_FMT_BYPASS);
+ info.max_buffer_size = m_numRenderBuffers;
+ info.optimal_buffer_size = m_numRenderBuffers;
+ return info;
+}
+
bool CRendererAML::RenderCapture(CRenderCapture* capture)
{
capture->BeginRender();
@@ -48,16 +106,28 @@ bool CRendererAML::RenderCapture(CRenderCapture* capture)
return true;
}
+int CRendererAML::GetImage(YV12Image *image, int source, bool readonly)
+{
+ if (image == nullptr)
+ return -1;
+
+ /* take next available buffer */
+ if (source == -1)
+ source = (m_iRenderBuffer + 1) % m_numRenderBuffers;
+
+ return source;
+}
+
void CRendererAML::AddVideoPictureHW(DVDVideoPicture &picture, int index)
{
- YUVBUFFER &buf = m_buffers[index];
+ BUFFER &buf = m_buffers[index];
if (picture.amlcodec)
buf.hwDec = picture.amlcodec->Retain();
}
void CRendererAML::ReleaseBuffer(int idx)
{
- YUVBUFFER &buf = m_buffers[idx];
+ BUFFER &buf = m_buffers[idx];
if (buf.hwDec)
{
CDVDAmlogicInfo *amli = static_cast<CDVDAmlogicInfo *>(buf.hwDec);
@@ -66,9 +136,14 @@ void CRendererAML::ReleaseBuffer(int idx)
}
}
-int CRendererAML::GetImageHook(YV12Image *image, int source, bool readonly)
+void CRendererAML::FlipPage(int source)
{
- return source;
+ if( source >= 0 && source < m_numRenderBuffers )
+ m_iRenderBuffer = source;
+ else
+ m_iRenderBuffer = (m_iRenderBuffer + 1) % m_numRenderBuffers;
+
+ return;
}
bool CRendererAML::IsGuiLayer()
@@ -104,37 +179,47 @@ EINTERLACEMETHOD CRendererAML::AutoInterlaceMethod()
return VS_INTERLACEMETHOD_NONE;
}
-bool CRendererAML::LoadShadersHook()
+void CRendererAML::Reset()
{
- CLog::Log(LOGNOTICE, "GL: Using AML render method");
- m_textureTarget = GL_TEXTURE_2D;
- m_renderMethod = RENDER_BYPASS;
- return false;
+ m_prevPts = 0;
+ m_diff_counter = 0;
}
-bool CRendererAML::RenderHook(int index)
-{
- return true;// nothing to be done for aml
-}
-
-bool CRendererAML::RenderUpdateVideoHook(bool clear, DWORD flags, DWORD alpha)
+void CRendererAML::RenderUpdate(bool clear, DWORD flags, DWORD alpha)
{
ManageRenderArea();
- CDVDAmlogicInfo *amli = static_cast<CDVDAmlogicInfo *>(m_buffers[m_iYV12RenderBuffer].hwDec);
+ CDVDAmlogicInfo *amli = static_cast<CDVDAmlogicInfo *>(m_buffers[m_iRenderBuffer].hwDec);
+ CAMLCodec *amlcodec = amli ? amli->getAmlCodec() : 0;
+
+ if(amlcodec)
+ amlcodec->PollFrame();
+
if (amli && amli->GetOmxPts() != m_prevPts)
{
m_prevPts = amli->GetOmxPts();
- SysfsUtils::SetInt("/sys/module/amvideo/parameters/omx_pts", amli->GetOmxPts());
- CAMLCodec *amlcodec = amli->getAmlCodec();
+ int pcrscr(get_pts("/sys/class/tsync/pts_pcrscr"));
+ m_diff_counter += static_cast<int>((pcrscr - m_prevPts)*1.1 / amli->GetAmlDuration());
+
+ if (abs(m_diff_counter) > 2)
+ {
+ int videopts(get_pts("/sys/class/tsync/pts_video"));
+ set_pts("/sys/class/tsync/pts_pcrscr", m_prevPts);
+ CLog::Log(LOGDEBUG, "RenderUpdate: Adjusting: ptsclock:%d ptsscr:%d vpts:%d diff:%d", m_prevPts, pcrscr, videopts, m_diff_counter);
+ pcrscr = m_prevPts;
+ m_diff_counter = 0;
+ }
+ else if (g_advancedSettings.CanLogComponent(LOGVIDEO))
+ {
+ int videopts(get_pts("/sys/class/tsync/pts_video"));
+ CLog::Log(LOGDEBUG, "RenderUpdate: ptsclock:%d ptsscr:%d vpts:%d diff:%d", m_prevPts, pcrscr, videopts, m_diff_counter);
+ }
+ SysfsUtils::SetInt("/sys/module/amvideo/parameters/omx_pts", pcrscr);
+
if (amlcodec)
amlcodec->SetVideoRect(m_sourceRect, m_destRect);
}
-
- usleep(10000);
-
- return true;
}
#endif
diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/RendererAML.h b/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/RendererAML.h
index 828f584a..bbef504 100644
--- a/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/RendererAML.h
+++ b/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/RendererAML.h
@@ -24,17 +24,29 @@
#if defined(HAS_LIBAMCODEC)
-#include "cores/VideoPlayer/VideoRenderers/LinuxRendererGLES.h"
+#include "cores/VideoPlayer/VideoRenderers/BaseRenderer.h"
-class CRendererAML : public CLinuxRendererGLES
+class CRendererAML : public CBaseRenderer
{
public:
CRendererAML();
virtual ~CRendererAML();
-
+
virtual bool RenderCapture(CRenderCapture* capture);
virtual void AddVideoPictureHW(DVDVideoPicture &picture, int index);
virtual void ReleaseBuffer(int idx);
+ virtual bool Configure(unsigned int width, unsigned int height, unsigned int d_width, unsigned int d_height, float fps, unsigned flags, ERenderFormat format, unsigned extended_formatl, unsigned int orientation);
+ virtual bool IsConfigured(){ return m_bConfigured; };
+ virtual CRenderInfo GetRenderInfo();
+ virtual int GetImage(YV12Image *image, int source = -1, bool readonly = false);
+ virtual void ReleaseImage(int source, bool preserve = false){};
+ virtual void FlipPage(int source);
+ virtual void PreInit(){};
+ virtual void UnInit(){};
+ virtual void Reset();
+ virtual void Update(){};
+ virtual void RenderUpdate(bool clear, unsigned int flags = 0, unsigned int alpha = 255);
+ virtual bool SupportsMultiPassRendering(){ return false; };
// Player functions
virtual bool IsGuiLayer();
@@ -47,16 +59,20 @@ class CRendererAML : public CLinuxRendererGLES
virtual EINTERLACEMETHOD AutoInterlaceMethod();
-protected:
+private:
+
+ int m_iRenderBuffer;
+ static const int m_numRenderBuffers = 3;
- // hooks for hw dec renderer
- virtual bool LoadShadersHook();
- virtual bool RenderHook(int index);
- virtual int GetImageHook(YV12Image *image, int source = AUTOSOURCE, bool readonly = false);
- virtual bool RenderUpdateVideoHook(bool clear, DWORD flags = 0, DWORD alpha = 255);
+ struct BUFFER
+ {
+ void *hwDec;
+ int duration;
+ } m_buffers[m_numRenderBuffers];
-private:
int m_prevPts;
+ bool m_bConfigured;
+ int m_diff_counter;
};
#endif
From 62209dbd993a5dfe1dc5ee6083c061bbc781ff7f Mon Sep 17 00:00:00 2001
From: Markus Pfau <pfau@peak3d.de>
Date: Fri, 18 Nov 2016 18:59:35 +0100
Subject: [PATCH 02/30] Increase size of render buffers (4)
---
xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/RendererAML.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/RendererAML.h b/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/RendererAML.h
index bbef504..0d9f126 100644
--- a/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/RendererAML.h
+++ b/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/RendererAML.h
@@ -62,7 +62,7 @@ class CRendererAML : public CBaseRenderer
private:
int m_iRenderBuffer;
- static const int m_numRenderBuffers = 3;
+ static const int m_numRenderBuffers = 4;
struct BUFFER
{
From d4742523c14dbed5724e80c5160334cf09cfedc7 Mon Sep 17 00:00:00 2001
From: Markus Pfau <pfau@peak3d.de>
Date: Fri, 18 Nov 2016 21:38:32 +0100
Subject: [PATCH 03/30] Limit timesize to be never > 2.0
---
xbmc/cores/VideoPlayer/DVDCodecs/Video/AMLCodec.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/AMLCodec.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Video/AMLCodec.cpp
index 0ab8567..56884af 100644
--- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/AMLCodec.cpp
+++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/AMLCodec.cpp
@@ -1896,7 +1896,7 @@ int CAMLCodec::Decode(uint8_t *pData, size_t iSize, double dts, double pts)
m_last_pts = m_cur_pts;
m_cur_pts = decode_pts;
}
- if ((rtn & VC_PICTURE)==0 || timesize < 1.0)
+ if (((rtn & VC_PICTURE)==0 && timesize < 2.0) || timesize < 1.0)
rtn |= VC_BUFFER;
if (g_advancedSettings.CanLogComponent(LOGVIDEO))
From 514370bfd06881cc972ebd7a6f29c1948f12c91c Mon Sep 17 00:00:00 2001
From: Markus Pfau <pfau@peak3d.de>
Date: Sat, 19 Nov 2016 20:47:47 +0100
Subject: [PATCH 04/30] sleep / vfs
---
xbmc/cores/VideoPlayer/DVDCodecs/Video/AMLCodec.cpp | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/AMLCodec.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Video/AMLCodec.cpp
index 56884af..6f2cfa9 100644
--- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/AMLCodec.cpp
+++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/AMLCodec.cpp
@@ -1886,6 +1886,8 @@ int CAMLCodec::Decode(uint8_t *pData, size_t iSize, double dts, double pts)
}
if (m_prefill_state == PREFILL_STATE_FILLING && timesize >= 1.0)
m_prefill_state = PREFILL_STATE_FILLED;
+ else if (m_prefill_state == PREFILL_STATE_FILLING)
+ Sleep(1);
}
int rtn(0);
@@ -1899,13 +1901,24 @@ int CAMLCodec::Decode(uint8_t *pData, size_t iSize, double dts, double pts)
if (((rtn & VC_PICTURE)==0 && timesize < 2.0) || timesize < 1.0)
rtn |= VC_BUFFER;
+ vframe_states_t vfs;
+ int fd(open("/dev/amvideo", RD_ONLY);
+ if(fd)
+ {
+ ioctl(fd, AMSTREAM_IOC_VF_STATUS, &vfs);
+ close(fd);
+ }