-
Notifications
You must be signed in to change notification settings - Fork 1
/
rk30_mirroring.c
1875 lines (1692 loc) · 61 KB
/
rk30_mirroring.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
/* drivers/video/mirroring.c
*
* Copyright (C) 2010 ROCKCHIP, Inc.
* author: jiangmingjun [email protected]
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* 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 General Public License for more details.
*
*/
#include <linux/miscdevice.h>
#include <linux/platform_device.h>
#include <linux/fs.h>
#include <linux/file.h>
#include <linux/mm.h>
#include <linux/list.h>
#include <linux/debugfs.h>
#include <linux/mempolicy.h>
#include <linux/sched.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include <asm/cacheflush.h>
#include <linux/fb.h>
#include <plat/ipp.h>
#include "linux/mirroring.h"
#include<linux/rk_fb.h>
#define MIRRORING_MIN_ALLOC PAGE_SIZE
#define MIRRORING_IS_PAGE_ALIGNED(addr) (!((addr) & (~PAGE_MASK)))
#define MIRRORING_DEBUG 0
#define MIRRORING_DEBUG_MSGS 0
#if MIRRORING_DEBUG_MSGS
#define DLOG(fmt,args...) \
do { printk(KERN_INFO "[%s:%s:%d] "fmt, __FILE__, __func__, __LINE__, \
##args); } \
while (0)
#else
#define DLOG(x...) do {} while (0)
#endif
//#define MIRRORING_WRITE_FILE
struct win_set {
volatile u32 y_offset;
volatile u32 c_offset;
};
struct win0_par {
u32 refcount;
u32 pseudo_pal[16];
u32 y_offset;
u32 c_offset;
u32 xpos; //size in panel
u32 ypos;
u32 xsize; //start point in panel
u32 ysize;
u32 format;
wait_queue_head_t wait;
struct win_set mirror;
struct win_set displ;
struct win_set done;
u8 par_seted;
u8 addr_seted;
};
/**
* struct for global mirroring info
*/
#if 1//def CONFIG_FB_MIRRORING
struct enc_buff_info{
u32 bitperpixel;
u32 mode;
u32 xaff;
u32 yaff;
u32 xpos;
u32 ypos;
u32 xsize;
u32 ysize;
u32 src_y;
u32 src_uv;
u32 dst_width;
u32 dst_height;
u32 dst_vir_w;
u32 dst_vir_h;
u32 y_offset;
u32 c_offset;
u32 src_width;
u32 src_height;
long long Frame_Time;
unsigned char* ui_buffer;
unsigned char* ui_buffer_map;
int rotation_flag;
};
struct mirroring_video_info{
u32 bitperpixel;
u32 mode;
u32 xaff;
u32 yaff;
u32 xpos;
u32 ypos;
u32 xsize;
u32 ysize;
u32 src_y;
u32 src_uv;
u32 dst_width;
u32 dst_height;
u32 rot_dst_width;
u32 rot_dst_height;
u32 rot_y_offset;
u32 rot_c_offset;
u32 src_width;
u32 src_height;
u32 set_flag;
int Last_rotation_flag;
int64_t Last_Frame_Time;
int64_t Mirroring_RGB_time;
int64_t Mirroring_YUV_time;
int64_t Mirroring_Cur_time;
int64_t Mirroring_Last_Input_time;
struct enc_buff_info enc_buff[4];
u32 buffer_num;
u32 avail_index;
u32 work_index;
volatile u32 avail_frame;
volatile u32 last_enc_frame;
int test_sign;
u32 frame_num;
bool vertical_screen_flag;
};
struct mirroring_audio_info{
volatile u32 buffer_size;
volatile u32 head_offset;
volatile u32 tail_offset;
volatile u32 data_len;
u32 nSamplePerFrame;
u32 nChannel;
u32 nBytePerSample;
u32 nBytePerFrame;
unsigned char* Out_Buffer;
int64_t *time_stamp;
unsigned char *audio_data;
};
struct mirroring_audio_param{
u32 buffer_size;
u32 nSamplePerFrame;
u32 nChannel;
u32 nBytePerSample;
u32 nBytePerFrame;
u32 Reserverd[7];
};
int rgb_time;
int yuv_time;
struct mirroring_info{
struct mirroring_video_info video_info;
struct mirroring_audio_info audio_info;
struct rw_semaphore rw_sem;
int video_start_sign;
int audio_start_sign;
int start_sign;
int volumn_open_sign;
int64_t start_time;
int rotation_flag;
int addr;
int local_port;
int remote_port;
int rk_flag;
int src_width;
int src_height;
int signal_weak;
int wireless_signal;
int framerate;
int src_y_back;
int src_uv_back;
};
struct mutex video_lock;
struct mutex audio_lock;
struct mutex mirroring_lock;
//int mirroring_prepare_para(struct fb_info *info);
//int mirroring_prepare_buff(struct fb_info *info);
//int mirroring_prepare(struct fb_info *info);
#endif
int rgb_rot_angle[2][4] = {
{IPP_ROT_90,IPP_ROT_0,IPP_ROT_270,IPP_ROT_180},
{IPP_ROT_0,IPP_ROT_270,IPP_ROT_180,IPP_ROT_90}
};
int yuv_rot_angle[2] = {IPP_ROT_0,IPP_ROT_270};
static int mirroring_count = 0;
static struct mirroring_info mirroring;
#define wdm_rwsem (mirroring.rw_sem)
extern int (*audio_data_to_mirroring)(void* data,int size,int channel);
extern int (*video_data_to_mirroring)(struct fb_info *info,u32 yuv_phy[2]);
extern int (*ipp_blit_sync)(const struct rk29_ipp_req *req);
#if 1//def CONFIG_FB_MIRRORING
unsigned long temp_vv;
static int frame_num = 0;
static int Is_Mirroring_Loaded()
{
int ret = -1;
if(mirroring_count > 0)
ret = 0;
return ret;
}
static int mirroring_video_close(struct mirroring_video_info *video_info);
static int mirroring_audio_close(void);
static int mirroring_prepare_para(struct fb_info *info,struct mirroring_video_info *video_info,struct enc_buff_info *enc_buff);
static int mirroring_prepare_buff(struct enc_buff_info *enc_buff);
static int mirroring_stop(void);
static int mirroring_start(void)
{
int ret = 0;
if(mirroring.start_sign == 1)
{
printk("mirrorring device is still opened ,So we restart it \n");
ret = mirroring_stop();
if(ret == 0)
mirroring.start_sign = 1;
else
printk("can't not close mirrorring device");
//ret = -1;
}
else
{
mirroring.start_sign = 1;
mirroring.addr = mirroring.local_port = mirroring.remote_port = 0;
mirroring.volumn_open_sign = 0;
mirroring.start_time = 0;
mirroring.rotation_flag = 0;
mirroring.signal_weak= 1;
mirroring.wireless_signal = 0;
mirroring.framerate = 25;
mirroring.rk_flag = 0;
}
return ret;
}
static int mirroring_stop(void)
{
int ret = 0;
if( mirroring.start_sign == 1)
{
if(mirroring.video_start_sign == 1)
{
mutex_lock(&video_lock);
ret = mirroring_video_close(&mirroring.video_info);
mutex_unlock(&video_lock);
}
if(mirroring.audio_start_sign == 1)
{
mutex_lock(&audio_lock);
ret = mirroring_audio_close();
mutex_unlock(&audio_lock);
}
mirroring.start_sign = 0;
}
else
{
ret = -1;
DLOG("mirrorring device is already closed\n");
}
return ret;
}
struct file* mirroring_filp;
mm_segment_t old_fs;
struct file* mirroring_filp_output;
mm_segment_t old_fs_output;
static int mirroring_audio_close(void);
static int mirroring_video_close(struct mirroring_video_info *video_info);
static int mirroring_audio_open(unsigned long *temp)
{
int ret = 0;
struct mirroring_audio_info *audio_info = &mirroring.audio_info;
struct timespec mTime;
if(mirroring.start_sign == 0)
{
printk("Apk didn't start when audio start \n");
return -1;
}
if(mirroring.audio_start_sign == 1)
{
printk("last mirrorring audio device is still opened ,something wrong\n");
return -2;
}
ktime_get_ts(&mTime);
memset(audio_info, 0, sizeof(struct mirroring_audio_info));
audio_info->Out_Buffer = NULL;
audio_info->buffer_size = 52;
audio_info->nSamplePerFrame = 1024;
audio_info->nBytePerSample = 2;
audio_info->nChannel = 2;
audio_info->nBytePerFrame = 4096;
audio_info->head_offset = 0;
audio_info->tail_offset = 0;
audio_info->data_len = 0;
if(audio_info->buffer_size <= 0 || (audio_info->nSamplePerFrame != 1024) ||
(audio_info->nBytePerFrame != 4096 ) || (audio_info->nChannel < 1 || audio_info->nChannel > 2 ) )
{
}
audio_info->audio_data = (unsigned char*)kmalloc(audio_info->buffer_size * audio_info->nBytePerFrame,GFP_KERNEL);
audio_info->time_stamp = (int64_t*)kmalloc(audio_info->buffer_size * sizeof(int64_t),GFP_KERNEL);
if(audio_info->audio_data == NULL || audio_info->time_stamp == NULL)
{
if(audio_info->time_stamp)
kfree((void *)audio_info->time_stamp);
if(audio_info->audio_data)
kfree((void *)audio_info->audio_data);
return -3;
}
mirroring.audio_start_sign = 1;
memset(audio_info->audio_data, 0,audio_info->buffer_size * audio_info->nBytePerFrame);
printk("audio_info->buffer_size * audio_info->nBytePerFrame timestamp %d audio_info->Out_Buffer %x time %lld %x %x\n",
audio_info->buffer_size * audio_info->nBytePerFrame,audio_info->time_stamp,audio_info->Out_Buffer,
(int64_t)mTime.tv_sec * 1000000ll + mTime.tv_nsec/1000
,__pa(audio_info->audio_data),__pa(audio_info->time_stamp));
#ifdef MIRRORING_WRITE_FILE
mirroring_filp = NULL;
mirroring_filp = filp_open("/data/test/input_cmp.pcm",O_CREAT|O_TRUNC|O_RDWR,0);
if (mirroring_filp)
{
old_fs = get_fs();
set_fs(get_ds());
}
mirroring_filp_output = NULL;
mirroring_filp_output = filp_open("/data/test/output_cmp.pcm",O_CREAT|O_TRUNC|O_RDWR,0);
if (mirroring_filp_output)
{
old_fs_output = get_fs();
set_fs(get_ds());
}
#endif
return ret;
}
static int mirroring_audio_close(void)
{
int ret = 0;
struct mirroring_audio_info *audio_info = &mirroring.audio_info;
#ifdef MIRRORING_WRITE_FILE
set_fs(old_fs);
filp_close(mirroring_filp,NULL);
set_fs(old_fs_output);
filp_close(mirroring_filp_output,NULL);
#endif
if(mirroring.audio_start_sign == 0 || mirroring.start_sign == 0)
{
printk("audio is already closed\n");
return -1;
}
if(audio_info->time_stamp)
kfree((void *)audio_info->time_stamp);
if(audio_info->audio_data)
kfree((void *)audio_info->audio_data);
audio_info->Out_Buffer = NULL;
mirroring.audio_start_sign = 0;
printk("mirroring_audio_close mirroring.audio_start_sign %d mirroring.start_sign %d\n",mirroring.audio_start_sign,mirroring.start_sign);
return ret;
}
static void mirroring_audio_set_para(struct mirroring_audio_param *param)
{
struct mirroring_audio_info *audio_info = &mirroring.audio_info;
audio_info->buffer_size = param->buffer_size;
audio_info->nSamplePerFrame = param->nSamplePerFrame;
audio_info->nChannel = param->nChannel;
audio_info->nBytePerSample = param->nBytePerSample;
audio_info->nBytePerFrame = param->nBytePerFrame;
DLOG("param %d %d %d %d %d audio_info %d %d %d %d %d",
param->buffer_size,param->nSamplePerFrame,param->nChannel,param->nBytePerSample,param->nBytePerFrame,
audio_info->buffer_size,audio_info->nSamplePerFrame,audio_info->nChannel,audio_info->nBytePerSample,audio_info->nBytePerFrame);
return;
}
static void mirroring_audio_set_vol(u32 temp_data)
{
mirroring.volumn_open_sign = temp_data;
return;
}
static int mirroring_audio_find_frame()
{
struct mirroring_audio_info *audio_info = &mirroring.audio_info;
int ret = 0;
if(audio_info->data_len >= 1)
{
audio_info->Out_Buffer = (void*)(&audio_info->audio_data[audio_info->head_offset * audio_info->nBytePerFrame]);
//mirroring_filp_output->f_op->write(mirroring_filp_output, audio_info->Out_Buffer, audio_info->nBytePerFrame, &mirroring_filp_output->f_pos);
audio_info->data_len --;
audio_info->head_offset ++;
audio_info->head_offset %= audio_info->buffer_size;
}
else
{
ret = -1;
}
return ret;
}
static int mirroring_audio_prepare(void* data,int size,int channel)
{
int ret = 0;
mutex_lock(&audio_lock);
if(mirroring.audio_start_sign && mirroring.start_sign)
{
unsigned long* temp = (unsigned long*)data;
struct mirroring_audio_info *audio_info = &mirroring.audio_info;
unsigned char* buf = data;
struct timespec mTime;
int audio_frame = size / audio_info->nBytePerFrame;
int64_t audio_time[4];
int i ;
ktime_get_ts(&mTime);
#if 1
for(i = 0; i < audio_frame; i++)
{
audio_time[i] = (int64_t)mTime.tv_sec * 1000000ll + mTime.tv_nsec/1000 + 23000 * i;
}
if(audio_info->tail_offset + audio_frame <= audio_info->buffer_size)
{
memcpy((void*)(&audio_info->audio_data[audio_info->tail_offset * audio_info->nBytePerFrame]), (void*)data,size);
memcpy((void*)(&audio_info->time_stamp[audio_info->tail_offset]),(void*)(audio_time),sizeof(int64_t)*audio_frame);
}
else
{
int part1 = audio_info->buffer_size - audio_info->tail_offset;// - 4 ;
int part2 = audio_info->tail_offset + audio_frame - audio_info->buffer_size;
memcpy((void*)(&audio_info->audio_data[audio_info->tail_offset * audio_info->nBytePerFrame]),
(void*)data,part1 * audio_info->nBytePerFrame);
memcpy((void*)(&audio_info->time_stamp[audio_info->tail_offset]),(void*)(&audio_time[0]),part1 * sizeof(int64_t));
memcpy((void*)(&audio_info->audio_data[0]),
(void*)data + part1 * audio_info->nBytePerFrame,part2 * audio_info->nBytePerFrame);
memcpy((void*)(&audio_info->time_stamp[0]),(void*)( &audio_time[part1]),part2 * sizeof(int64_t));
// }
// if(audio_info->tail_offset + 4 > audio_info->buffer_size)
// {
}
audio_info->tail_offset += audio_frame;
audio_info->tail_offset %= audio_info->buffer_size;
if(audio_info->data_len + audio_frame < audio_info->buffer_size)
{
audio_info->data_len += audio_frame;
}
else
{
audio_info->head_offset=audio_info->tail_offset;
audio_info->data_len = audio_info->buffer_size;
}
// if(mirroring.volumn_open_sign==0)
#else
// {
memcpy((void*)(&audio_info->audio_data[audio_info->tail_offset * audio_info->nBytePerFrame]), (void*)data,size);
memcpy((void*)(&audio_info->time_stamp[audio_info->tail_offset]),(void*)(&audio_time),sizeof(int64_t));
audio_info->tail_offset ++;
audio_info->tail_offset %= audio_info->buffer_size;
if(audio_info->data_len + 1 < audio_info->buffer_size)
{
audio_info->data_len ++;
}
else
{
audio_info->head_offset=audio_info->tail_offset;
audio_info->data_len = audio_info->buffer_size;
}
#endif
if(mirroring.start_sign && mirroring.volumn_open_sign == 0)
memset((void*)data,0,size);
}
else
{
//DLOG("mirroring_video not open\n");
ret = AUDIO_ENCODER_CLOSED;
}
mutex_unlock(&audio_lock);
return ret;
}/*
mirroring_video can be opened once at a time.
Other user must wait for last open closed.
*/
static int mirroring_video_open(unsigned long *temp)
{
struct mirroring_video_info *video_info = &mirroring.video_info;
int i;
int ret =0 ;
struct timespec video_start_time;
printk("mirroring_video_open 1\n");
if(mirroring.start_sign == 0)
{
printk("Apk didn't start when video start ");
return -1;
}
if(mirroring.video_start_sign == 1)
{
printk("last mirroring_video still opened ,something wrong\n");
return -1;
}
memset(&mirroring.video_info,0,sizeof(struct mirroring_video_info));
video_info->Last_rotation_flag = -1;
video_info->buffer_num = temp[2];
video_info->dst_width = (temp[0] + 15) & 0xfff0;
video_info->dst_height = temp[1];//(temp[1] + 15) & 0xfff0;
video_info->xsize = video_info->dst_width;
video_info->ysize = video_info->dst_height;
video_info->src_width = mirroring.src_width;
video_info->src_height = mirroring.src_height;
video_info->last_enc_frame = -1;
if((video_info->buffer_num > 2 || video_info->buffer_num < 1) || (video_info->dst_width > 1280 || video_info->dst_width < 320) ||
(video_info->dst_height > 1280 || video_info->dst_height < 320) || (mirroring.src_width == 0) || (mirroring.src_height == 0))
{
printk("video init parameter error %d %d %d %d %d \n",video_info->buffer_num,video_info->dst_width,video_info->dst_height,
mirroring.src_width, mirroring.src_height);
return -1;
}
for(i = 0; i < video_info->buffer_num; i++)
{
video_info->enc_buff[i].ui_buffer= (unsigned char*)temp[i+3];
video_info->enc_buff[i].ui_buffer_map= ioremap(temp[i+3],video_info->dst_width * video_info->dst_height * 4);
memset(video_info->enc_buff[i].ui_buffer_map,0,video_info->dst_width * video_info->dst_height * 4 );
if(video_info->enc_buff[i].ui_buffer_map == NULL)
{
ret = -1;
break;
}
}
if(ret < 0)
{
printk("ui_buffer_map is NULL \n");
for(i = 0; i < video_info->buffer_num; i++)
{
if(video_info->enc_buff[i].ui_buffer_map!=0)
{
iounmap(video_info->enc_buff[i].ui_buffer_map);
video_info->enc_buff[i].ui_buffer_map = 0;
video_info->enc_buff[i].ui_buffer = 0;
}
}
return -1;
}
if(video_info->dst_height < video_info->dst_width)
{
video_info->rot_dst_height = video_info->dst_height;
if(mirroring.src_height > mirroring.src_width)
video_info->rot_dst_width = ((video_info->dst_height * mirroring.src_width) / mirroring.src_height)& 0xfffc;
else
video_info->rot_dst_width = ((video_info->dst_height * mirroring.src_height )/ mirroring.src_width)& 0xfffc;
}
else
{
video_info->rot_dst_width = video_info->dst_width;
if(mirroring.src_height > mirroring.src_width)
video_info->rot_dst_height = ((video_info->dst_width * mirroring.src_width) / mirroring.src_height)& 0xfffc;
else
video_info->rot_dst_height = ((video_info->dst_width * mirroring.src_height) / mirroring.src_width)& 0xfffc;
}
video_info->rot_dst_width = (video_info->rot_dst_width + 15) & 0xfff0;
video_info->rot_dst_height = (video_info->rot_dst_height + 15) & 0xfff0;
printk("video_info->rot_dst_width %d video_info->rot_dst_height %d video_info->dst_height %d %d\n",
video_info->rot_dst_width,video_info->rot_dst_height,video_info->dst_width,video_info->dst_height);
if(video_info->src_width< video_info->src_height)
video_info->vertical_screen_flag = 1;
mirroring.video_start_sign = 1;
{
struct enc_buff_info *enc_buff = &video_info->enc_buff[0];
ktime_get_ts(&video_start_time);
enc_buff->bitperpixel =16;// mirroring_info.bitperpixel_fb1;
enc_buff->rotation_flag = IPP_ROT_0 ;
enc_buff->dst_width = video_info->dst_width;
enc_buff->dst_height = video_info->dst_height;
enc_buff->src_width = video_info->src_width;
enc_buff->src_height = video_info->src_height;
enc_buff->dst_vir_w = video_info->dst_width;
enc_buff->dst_vir_h = video_info->dst_height;
enc_buff->y_offset = enc_buff->c_offset = 0;
enc_buff->mode = 0;
enc_buff->src_y = video_info->enc_buff[0].ui_buffer;//mirroring.src_y_back;//video_info->enc_buff[0].ui_buffer;//info->fix.smem_start + par->y_offset;//info->screen_base + par->y_offset;//info_buffer[8];
enc_buff->Frame_Time = video_info->Mirroring_RGB_time =(long long)video_start_time.tv_sec * 1000000ll + video_start_time.tv_nsec/1000;
enc_buff = &video_info->enc_buff[1];
enc_buff->bitperpixel = 16;// mirroring_info.bitperpixel_fb1;
enc_buff->rotation_flag = IPP_ROT_0 ;
enc_buff->dst_width = video_info->dst_width;
enc_buff->dst_height = video_info->dst_height;
enc_buff->src_width = video_info->src_width;
enc_buff->src_height = video_info->src_height;
enc_buff->dst_vir_w = video_info->dst_width;
enc_buff->dst_vir_h = video_info->dst_height;
enc_buff->y_offset = enc_buff->c_offset = 0;
enc_buff->mode = 0;
enc_buff->src_y = video_info->enc_buff[1].ui_buffer;//mirroring.src_y_back;//video_info->enc_buff[1].ui_buffer;//info->fix.smem_start + par->y_offset;//info->screen_base + par->y_offset;//info_buffer[8];
enc_buff->Frame_Time = video_info->Mirroring_RGB_time =(long long)video_start_time.tv_sec * 1000000ll + video_start_time.tv_nsec/1000;
mirroring.video_info.Mirroring_Last_Input_time = (long long)video_start_time.tv_sec * 1000000ll + video_start_time.tv_nsec/1000;
// mirroring_prepare_para(info,video_info,enc_buff);
//ret = mirroring_prepare_buff(enc_buff);
// memcpy(video_info->enc_buff[1].ui_buffer_map,video_info->enc_buff[0].ui_buffer_map,video_info->dst_width * video_info->dst_height * 4);
}
DLOG("video_info->dst_width %d video_info->dst_height %d ui_buffer %x %x size %d\n",
video_info->dst_width,video_info->dst_height,video_info->enc_buff[0].ui_buffer,video_info->enc_buff[1].ui_buffer,temp[2]);
rgb_time = yuv_time = 0;
return ret;
}
/*
close mirroring_video .
release resources.
*/
static int mirroring_video_close(struct mirroring_video_info *video_info)
{
int i ;
int ret = 0;
if(mirroring.video_start_sign == 0 || mirroring.start_sign == 0)
{
printk("something is not okay with mirroring video in close\n");
return -1;
}
mirroring.video_start_sign = 0;
printk("mirroring_video_close video_info->dst_width %d video_info->dst_height %d ui_buffer %x %x ui_buffer_map %x %x\n",
video_info->dst_width,video_info->dst_height,video_info->enc_buff[0].ui_buffer,video_info->enc_buff[1].ui_buffer,
video_info->enc_buff[0].ui_buffer_map,video_info->enc_buff[1].ui_buffer_map);
for(i = 0; i < video_info->buffer_num; i++)
{
DLOG("closebuf ui_buffer %x ui_buffer_map %x ui_buffer_map addr %x mirroring_info.buffer_num %d i %d\n",
(unsigned int)video_info->enc_buff[i].ui_buffer,(unsigned int)video_info->enc_buff[i].ui_buffer_map,(unsigned long)(&video_info->enc_buff[i].ui_buffer_map),video_info->buffer_num,i);
if(video_info->enc_buff[i].ui_buffer_map!=0)
{
iounmap(video_info->enc_buff[i].ui_buffer_map);
video_info->enc_buff[i].ui_buffer_map = 0;
video_info->enc_buff[i].ui_buffer = 0;
}
}
return ret;
}
/*
get video frame
it return -1 when no frame is availiable
*/
static int mirroring_video_find_frame(unsigned long* temp_data,struct mirroring_video_info *video_info)
{
int ret = 0;
struct timespec temptime;
ktime_get_ts(&temptime);
video_info->Mirroring_Cur_time = (int64_t)temptime.tv_sec * 1000000ll + temptime.tv_nsec/1000;
DLOG("mirroring_find_frame video_info->buffer_num %d avail_index %d avail_frame %d work_index %d testIgn %d time %lld curtime %lld last_time %lld %lld %lld yuv rgb time %lld %lld yuv_time %d\n",
video_info->buffer_num, video_info->avail_index,video_info->avail_frame,video_info->work_index,video_info->test_sign,video_info->enc_buff[video_info->avail_index].Frame_Time,
video_info->Mirroring_Cur_time,video_info->Last_Frame_Time,video_info->enc_buff[video_info->avail_index].Frame_Time,
video_info->enc_buff[1-video_info->avail_index].Frame_Time,video_info->Mirroring_YUV_time
,video_info->Mirroring_RGB_time ,yuv_time);
temp_data[7] = 0;
if(video_info->avail_frame)
{
DLOG (" suitable available frame cur_Frame_Time %lld lasttime %lld delta time %lld \n"
,video_info->enc_buff[video_info->avail_index].Frame_Time,video_info->Last_Frame_Time,
video_info->enc_buff[video_info->avail_index].Frame_Time - video_info->Last_Frame_Time);
if(video_info->enc_buff[video_info->avail_index].Frame_Time - video_info->Last_Frame_Time < 25000ll)
{
temp_data[7] = 1;
video_info->avail_index++;
video_info->avail_index %= video_info->buffer_num;
video_info->avail_frame--;
video_info->frame_num++;
yuv_time = rgb_time = 0;
return 0;
}
if(video_info->Last_Frame_Time > video_info->enc_buff[video_info->avail_index].Frame_Time)
{
DLOG("mirroring_find_frame error avail_index %d avail_frame %d work_index %d testIgn %d time %lld curtime %lld last_time %lld %lld %lld yuv rgb time %lld %lld yuv_time %d\n",
video_info->avail_index,video_info->avail_frame,video_info->work_index,video_info->test_sign,video_info->enc_buff[video_info->avail_index].Frame_Time,
video_info->Mirroring_Cur_time,video_info->Last_Frame_Time,video_info->enc_buff[video_info->avail_index].Frame_Time,
video_info->enc_buff[1-video_info->avail_index].Frame_Time,video_info->Mirroring_YUV_time
,video_info->Mirroring_RGB_time,yuv_time);
video_info->test_sign = 2;
}
video_info->Last_Frame_Time = video_info->enc_buff[video_info->avail_index].Frame_Time;
}
else
{
if(video_info->Mirroring_Cur_time > video_info->Last_Frame_Time + 100000ll )//&& video_info->frame_num!=0)
{
DLOG("no avail video_info->Mirroring_Cur_time %lld Last_Frame_Time %lld Mirroring_Last_Input_time %lld delta %lld %lld\n",
video_info->Mirroring_Cur_time,video_info->Last_Frame_Time,video_info->Mirroring_Last_Input_time ,
video_info->Mirroring_Cur_time - video_info->Last_Frame_Time,video_info->Mirroring_Cur_time - video_info->Mirroring_Last_Input_time);
DLOG("mirroring_find_frame wait second avail_index %d avail_frame %d work_index %d frame_num %d testIgn %d time %lld curtime %lld last_time %lld %lld %lld yuv rgb time %lld %lld yuv_time %d\n",
video_info->avail_index,video_info->avail_frame,video_info->work_index,video_info->frame_num,
video_info->test_sign,video_info->enc_buff[video_info->avail_index].Frame_Time,
video_info->Mirroring_Cur_time,video_info->Last_Frame_Time,video_info->enc_buff[video_info->avail_index].Frame_Time,
video_info->enc_buff[1- video_info->avail_index].Frame_Time,video_info->Mirroring_YUV_time
,video_info->Mirroring_RGB_time,yuv_time);
video_info->test_sign = 3;
video_info->Last_Frame_Time =video_info->Mirroring_Cur_time;
if(video_info->mode == 0 )
{
video_info->Mirroring_RGB_time = video_info->Mirroring_Cur_time;
}
else
{
video_info->Mirroring_YUV_time = video_info->Mirroring_Cur_time;
}
video_info->avail_index--;
video_info->avail_index %= video_info->buffer_num;
video_info->avail_frame++;
video_info->enc_buff[video_info->avail_index].Frame_Time = video_info->Mirroring_Cur_time;
DLOG("mirroring_find_frame wait second avail_index %d avail_frame %d work_index %d frame_num %d testIgn %d time %lld curtime %lld last_time %lld %lld %lld yuv rgb time %lld %lld yuv_time %d\n",
video_info->avail_index,video_info->avail_frame,video_info->work_index,video_info->frame_num,
video_info->test_sign,video_info->enc_buff[video_info->avail_index].Frame_Time,
video_info->Mirroring_Cur_time,video_info->Last_Frame_Time,video_info->enc_buff[video_info->avail_index].Frame_Time,
video_info->enc_buff[1- video_info->avail_index].Frame_Time,video_info->Mirroring_YUV_time);
}
else
{
temp_data[7] = 1;
DLOG ("no avail frame \n");
return 0;
}
}
temp_data[0] = (video_info->enc_buff[video_info->avail_index].bitperpixel << 16);
temp_data[0] |= video_info->enc_buff[video_info->avail_index].mode;
temp_data[1] = video_info->avail_index ;
memcpy(&temp_data[2],&video_info->enc_buff[video_info->avail_index].Frame_Time,8);
memcpy(&temp_data[4],&video_info->Mirroring_Cur_time,8);
temp_data[6] = video_info->enc_buff[video_info->avail_index].rotation_flag;
video_info->last_enc_frame = video_info->avail_index;
video_info->avail_index++;
video_info->avail_index %= video_info->buffer_num;
video_info->avail_frame--;
video_info->frame_num++;
yuv_time = rgb_time = 0;
return ret;
}
#if 1
int mirroring_prepare_para(struct fb_info *info,struct mirroring_video_info *video_info,struct enc_buff_info *enc_buff)
{
//struct rk29fb_inf *inf = dev_get_drvdata(info->device);
struct rk_fb_inf *inf = dev_get_drvdata(info->device);
struct fb_var_screeninfo *var = &info->var;
int ret = 0;
struct layer_par *par = NULL;
struct fb_fix_screeninfo * fix = &info->fix;
struct rk_lcdc_device_driver *dev_drv = (struct rk_lcdc_device_driver *)info->par;
int layer_id = 0;
#if 1
layer_id = dev_drv->fb_get_layer(dev_drv,info->fix.id);
#else
layer_id = get_fb_layer_id(fix);
#endif
if (layer_id < 0)
{
return -ENODEV;
}
else
{
par = dev_drv->layer_par[layer_id];
}
video_info->mode = inf->video_mode;
if(inf->video_mode == 0 )
{
int rotation = 0;
#if defined(CONFIG_FB_ROTATE)
int orientation = orientation = 270 - CONFIG_ROTATE_ORIENTATION;
switch(orientation)
{
case 0:
rotation = 0;
break;
case 90:
rotation = 1;
break;
case 180:
rotation = 2;
break;
case 270:
rotation = 3;
break;
default:
rotation = 3;
break;
}
#endif
rotation += mirroring.rotation_flag;
rotation %= 4;
if(par->format == 1)
{
enc_buff->bitperpixel = 16;
enc_buff->rotation_flag = 0 + rgb_rot_angle[video_info->vertical_screen_flag][rotation];
}
else
{
enc_buff->bitperpixel =32;// mirroring_info.bitperpixel_fb1;
enc_buff->rotation_flag = 8 + rgb_rot_angle[video_info->vertical_screen_flag][rotation];
}
enc_buff->dst_width = video_info->dst_width;
enc_buff->dst_height = video_info->dst_height;
enc_buff->src_width = video_info->src_width;
enc_buff->src_height = video_info->src_height;
enc_buff->dst_vir_w = video_info->dst_width;
enc_buff->dst_vir_h = video_info->dst_height;
enc_buff->y_offset = enc_buff->c_offset = 0;
enc_buff->mode = 0;
enc_buff->src_y = info->fix.smem_start + par->y_offset;//info->screen_base + par->y_offset;//info_buffer[8];
enc_buff->src_uv = info->fix.smem_start + par->y_offset + video_info->src_width * video_info->src_height;//dst_width*dst_height;//+ par->y_offset + dst_width*dst_height;//info_buffer[9];
enc_buff->Frame_Time = video_info->Mirroring_RGB_time;//.tv_sec;
//if(0)//rotation_sign == IPP_ROT_90 || rotation_sign == IPP_ROT_270)
{
if(video_info->dst_width > video_info->dst_height)
{
if((enc_buff->src_width >= enc_buff->src_height && (mirroring.rotation_flag == 0 || mirroring.rotation_flag == 2))
||(enc_buff->src_width < enc_buff->src_height && (mirroring.rotation_flag == 0 || mirroring.rotation_flag == 2)))
{
enc_buff->dst_height = video_info->rot_dst_height;
enc_buff->dst_width = video_info->rot_dst_width;
if(par->format == 1)
enc_buff->y_offset =((enc_buff->dst_vir_w - enc_buff->dst_width ) ) & 0xfff0;
else
enc_buff->y_offset = ((enc_buff->dst_vir_w - enc_buff->dst_width ) * 2) & 0xfff0;
}
}
else
{
if((enc_buff->src_width < enc_buff->src_height && (mirroring.rotation_flag == 1 || mirroring.rotation_flag == 3))
||(enc_buff->src_width >= enc_buff->src_height && (mirroring.rotation_flag == 1 || mirroring.rotation_flag == 3)))
{
enc_buff->dst_width = video_info->rot_dst_width;
enc_buff->dst_height = video_info->rot_dst_height;
if(par->format == 1)
enc_buff->y_offset =((enc_buff->dst_vir_h - enc_buff->dst_height ) / 2) * enc_buff->dst_vir_w * 2;
else
enc_buff->y_offset = ((enc_buff->dst_vir_h - enc_buff->dst_height ) / 2) * enc_buff->dst_vir_w * 4;
}
}
}
DLOG("width height %d %d vir_w %d vir_h %d y_offset %d c_offset %d src %d %d mirroring.rotation_flag %d rotangle %d dst %d %d par->format %d rot w h %d %d\n",
enc_buff->dst_width,enc_buff->dst_height,enc_buff->dst_vir_w,enc_buff->dst_vir_h,enc_buff->y_offset,
enc_buff->c_offset,enc_buff->src_width,enc_buff->src_height,mirroring.rotation_flag,enc_buff->rotation_flag,
video_info->dst_width,video_info->dst_height,par->format,video_info->rot_dst_width,video_info->rot_dst_height);
// printk("mode 0 enc_buff.src0.w %d %d enc_buff %x enc_buff->mode %d bit %d format %d\n",enc_buff->src_width,enc_buff->src_height,(unsigned long)enc_buff
// ,enc_buff->mode,enc_buff->bitperpixel,par->format);
}
else
{
struct fb_var_screeninfo *var = &info->var;
enc_buff->dst_width = video_info->dst_width;
enc_buff->dst_height = video_info->dst_height;
enc_buff->src_width = var->xres;
enc_buff->src_height = var->yres;
enc_buff->dst_vir_w = video_info->dst_width;
enc_buff->dst_vir_h = video_info->dst_height;
enc_buff->y_offset = enc_buff->c_offset = 0;
enc_buff->bitperpixel = 16;
enc_buff->mode = 1;
enc_buff->src_y = video_info->src_y;
enc_buff->src_uv = video_info->src_uv;
enc_buff->Frame_Time = (long long)video_info->Mirroring_YUV_time;//.tv_sec ;
enc_buff->rotation_flag = 16 + yuv_rot_angle[video_info->vertical_screen_flag];
if(video_info->dst_width <= video_info->dst_height && enc_buff->src_width > enc_buff->src_height)
{
enc_buff->dst_width = video_info->dst_width;
enc_buff->dst_height = (video_info->dst_width * enc_buff->src_height / enc_buff->src_width)& 0xfff0;;
if(enc_buff->dst_height > video_info->dst_height)
enc_buff->dst_height = video_info->dst_height;
enc_buff->y_offset =((enc_buff->dst_vir_h - enc_buff->dst_height ) / 2) * enc_buff->dst_vir_w;
enc_buff->c_offset =((enc_buff->dst_vir_h - enc_buff->dst_height ) / 2) * enc_buff->dst_vir_w /2;
}else if(video_info->dst_width > video_info->dst_height && enc_buff->src_height < enc_buff->src_width)
{
enc_buff->dst_height = video_info->dst_height;
enc_buff->dst_width = (video_info->dst_height * enc_buff->src_width / enc_buff->src_height)& 0xfff0;;
if(enc_buff->dst_width > video_info->dst_width)
enc_buff->dst_width = video_info->dst_width;
enc_buff->y_offset =((enc_buff->dst_vir_h - enc_buff->dst_height ) / 2) * enc_buff->dst_vir_w;
enc_buff->c_offset =((enc_buff->dst_vir_h - enc_buff->dst_height ) / 2) * enc_buff->dst_vir_w /2;
}
DLOG("yuv width height %d %d vir_w %d vir_h %d y_offset %d c_offset %d src %d %d mirroring.rotation_flag %d rotangle %d dst %d %d rot w h %d %d\n",
enc_buff->dst_width,enc_buff->dst_height,enc_buff->dst_vir_w,enc_buff->dst_vir_h,enc_buff->y_offset,
enc_buff->c_offset,enc_buff->src_width,enc_buff->src_height,mirroring.rotation_flag,enc_buff->rotation_flag,
video_info->dst_width,video_info->dst_height,video_info->rot_dst_width,video_info->rot_dst_height);
}
if((enc_buff->dst_vir_w != enc_buff->dst_width || enc_buff->dst_vir_h != enc_buff->dst_height ) && video_info->Last_rotation_flag != enc_buff->rotation_flag)//mirroring_info.Last_rotation_flag != enc_buff->rotation_sign)
{
int i;
if(enc_buff->rotation_flag & 0x8)
{
for(i = 0; i < video_info->buffer_num; i++)
{
memset(video_info->enc_buff[i].ui_buffer_map,0,enc_buff->dst_vir_w * enc_buff->dst_vir_h * 4);//dst_width*dst_height);
}
}
else if((enc_buff->rotation_flag & 0x8 )== 0 && (enc_buff->rotation_flag & 0x10 )== 0)
{
for(i = 0; i < video_info->buffer_num; i++)
{
memset(video_info->enc_buff[i].ui_buffer_map,0,enc_buff->dst_vir_w * enc_buff->dst_vir_h * 2);//dst_width*dst_height);
}
}
else if(enc_buff->rotation_flag & 0x10 )
{
for(i = 0; i < video_info->buffer_num; i++)
{
memset(video_info->enc_buff[i].ui_buffer_map,0,enc_buff->dst_vir_w * enc_buff->dst_vir_h);//dst_width*dst_height);
memset(video_info->enc_buff[i].ui_buffer_map + enc_buff->dst_vir_w * enc_buff->dst_vir_h,0x80,enc_buff->dst_vir_w * enc_buff->dst_vir_h / 2);//dst_width*dst_height);
}
}
// memset(ui_buffer_map,0,enc_buff->dst_vir_w * enc_buff->dst_vir_h * 4);//dst_width*dst_height);
//memset(ui_buffer_map + enc_buff->dst_height * enc_buff->dst_width, 0x80,enc_buff->dst_height * enc_buff->dst_width / 2);//dst_width*dst_height,0x80,dst_width*dst_height/2);
DLOG("rotation change mirroring_info.Last_rotation_flag %d enc_buff->rotation_sign %d\n",video_info->Last_rotation_flag,enc_buff->rotation_flag);
}
video_info->Last_rotation_flag = enc_buff->rotation_flag;
return ret;
}
#endif
int mirroring_prepare_buff(struct enc_buff_info *enc_buff)
{
struct rk29_ipp_req overlay_req;
struct rk29_ipp_req overlay_req_1;
int err = 0;
memset(&overlay_req, 0 , sizeof(overlay_req));
memset(&overlay_req_1, 0 , sizeof(overlay_req_1));
//printk("inf->video_mode %d\n",inf->video_mode);
if(enc_buff->mode == 0 )
{
overlay_req.src0.YrgbMst = enc_buff->src_y;//info->fix.smem_start + par->y_offset;//info->screen_base + par->y_offset;//info_buffer[8];
overlay_req.src0.CbrMst = enc_buff->src_uv;//info->fix.smem_start + par->y_offset + enc_buff->src_width * enc_buff->src_height;//dst_width*dst_height;//+ par->y_offset + dst_width*dst_height;//info_buffer[9];
overlay_req.src0.w = enc_buff->src_width ;//dst_width;//info_buffer[2];
overlay_req.src0.h = enc_buff->src_height ;//dst_height;//info_buffer[3];
overlay_req.src0.fmt = (enc_buff->bitperpixel == 16) ? 1 : 0;//3;
overlay_req.dst0.YrgbMst = (unsigned long)(enc_buff->ui_buffer + enc_buff->y_offset);//overlay_buffer + info_buffer[4] + info_buffer[5] * dst_width;
overlay_req.dst0.CbrMst = (unsigned long)(enc_buff->ui_buffer + enc_buff->dst_vir_w * enc_buff->dst_height + enc_buff->c_offset);//dst_width*dst_height;//(unsigned char*) overlay_buffer + dst_width*dst_height +info_buffer[4] + ( info_buffer[5] * dst_width) / 2;// info_buffer[6] * info_buffer[7];
overlay_req.dst0.w = enc_buff->dst_width ;//dst_width;//info_buffer[6];
overlay_req.dst0.h = enc_buff->dst_height ;//dst_height;//info_buffer[7];
overlay_req.dst0.fmt = (enc_buff->bitperpixel== 16) ? 1 : 0;//3;3;
overlay_req.deinterlace_enable = 0;
overlay_req.timeout = 1000000;
overlay_req.src_vir_w = enc_buff->src_width ;//dst_width;//info_buffer[2];
overlay_req.dst_vir_w = enc_buff->dst_vir_w ;//dst_width;
//printk("mode 0 overlay_req.src0.w %d %d enc_buff %x\n",overlay_req.src0.w,overlay_req.src0.h,(unsigned long)enc_buff);
overlay_req.flag = enc_buff->rotation_flag & 0x7;
err = ipp_blit_sync(&overlay_req);
if(err)
goto MIRRORING_IPP_ERROR;
//printk("mode 0err %d w h fmt time out %d %d %d %d",err,overlay_req.src0.w,overlay_req.src0.h,overlay_req.src0.fmt,overlay_req.timeout);
DLOG("dst0.w %d dst0.h %d src0.w %d src0.h %d dst_vir_w %d src_vir_w %d overlay_req.flag x %d y %d\n",
overlay_req.dst0.w,overlay_req.dst0.h,overlay_req.src0.w,overlay_req.src0.h,overlay_req.dst_vir_w ,