1 | #ifndef SHOWIFRAME_H
|
---|
2 | #define SHOWIFRAME_H
|
---|
3 |
|
---|
4 | #define VIDEO_STREAMTYPE_MPEG2 0
|
---|
5 | #define VIDEO_STREAMTYPE_MPEG4_H264 1
|
---|
6 |
|
---|
7 | void singlepicthread(struct stimerthread* self, struct dvbdev* node , char* filename)
|
---|
8 | {
|
---|
9 | status.singlepicthreadstatus += 1;
|
---|
10 | printf("singlepicthread (%d) start filename: %s\n", status.singlepicthreadstatus, filename);
|
---|
11 |
|
---|
12 | if(status.singlepicthread != NULL || self == NULL)
|
---|
13 | {
|
---|
14 | return;
|
---|
15 | }
|
---|
16 | status.singlepicthread = self;
|
---|
17 |
|
---|
18 |
|
---|
19 | int count = 0;
|
---|
20 | /*
|
---|
21 | while(count < 2)
|
---|
22 | {
|
---|
23 | sleep(1);
|
---|
24 | count++;
|
---|
25 | }
|
---|
26 | */
|
---|
27 | // usleep(150000);
|
---|
28 |
|
---|
29 | showsinglepic(node, filename);
|
---|
30 |
|
---|
31 | status.singlepicthread = NULL;
|
---|
32 | printf("singlepicthread (%d) end filename: %s\n", status.singlepicthreadstatus, filename);
|
---|
33 | }
|
---|
34 |
|
---|
35 | void showsinglepic(struct dvbdev* node, char* filename)
|
---|
36 | {
|
---|
37 | printf("showsinglepic (%d) start filename: %s\n", status.singlepicthreadstatus, filename);
|
---|
38 |
|
---|
39 | if (status.singlepicfd >= 0)
|
---|
40 | {
|
---|
41 | printf("showsinglepic (%d) videostop filename: %s\n", status.singlepicthreadstatus, filename);
|
---|
42 | videostop(node, 1);
|
---|
43 | videoselectsource(node, VIDEO_SOURCE_DEMUX);
|
---|
44 | videoclose(node, -1);
|
---|
45 | node = NULL;
|
---|
46 | }
|
---|
47 |
|
---|
48 | printf("showsinglepic (%d) end filename: %s\n", status.singlepicthreadstatus, filename);
|
---|
49 | }
|
---|
50 |
|
---|
51 | //flag 0: stop service
|
---|
52 | //flag 1: not stop service
|
---|
53 | int singlepicstart(const char *filename, int flag)
|
---|
54 | {
|
---|
55 | printf("---start----------------------\n");
|
---|
56 | printf("singlepicstart filename: %s\n", filename);
|
---|
57 |
|
---|
58 | int ret = 0;
|
---|
59 |
|
---|
60 | if(status.aktservice->type != STILLPIC)
|
---|
61 | {
|
---|
62 | if(flag == 0)
|
---|
63 | {
|
---|
64 | ret = servicestop(status.aktservice, 0, 1);
|
---|
65 | if(ret == 1) return 1;
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | int fd = open(filename, O_RDONLY);
|
---|
70 | if(fd >= 0)
|
---|
71 | {
|
---|
72 |
|
---|
73 |
|
---|
74 | struct dvbdev* videonode = NULL;
|
---|
75 | struct stat s;
|
---|
76 | fstat(fd, &s);
|
---|
77 |
|
---|
78 | if(checkchipset("3798MV200") == 1 || status.aktservice->type != STILLPIC)
|
---|
79 | {
|
---|
80 | if(status.aktservice->videodev != NULL)
|
---|
81 | {
|
---|
82 | videoclose(status.aktservice->videodev, -1);
|
---|
83 | status.aktservice->videodev = NULL;
|
---|
84 | }
|
---|
85 |
|
---|
86 | videonode = videoopen(0, 0);
|
---|
87 | videoselectsource(videonode, VIDEO_SOURCE_MEMORY);
|
---|
88 |
|
---|
89 | videosetformat(videonode, VIDEO_FORMAT_16_9);
|
---|
90 | videosetstreamtype(videonode, MPEGV);
|
---|
91 | videoplay(videonode);
|
---|
92 |
|
---|
93 | }
|
---|
94 | else
|
---|
95 | videonode = status.aktservice->videodev;
|
---|
96 |
|
---|
97 |
|
---|
98 | if(videonode != NULL)
|
---|
99 | {
|
---|
100 | struct video_still_picture stillpic;
|
---|
101 | char* iframe = NULL;
|
---|
102 |
|
---|
103 | iframe = malloc(s.st_size);
|
---|
104 | if(iframe == NULL)
|
---|
105 | {
|
---|
106 | err("no mem");
|
---|
107 | close(fd);
|
---|
108 | return 1;
|
---|
109 | }
|
---|
110 |
|
---|
111 | status.aktservice->type = STILLPIC;
|
---|
112 | status.aktservice->videodev = videonode;
|
---|
113 | status.singlepicfd = status.aktservice->videodev->fd;
|
---|
114 |
|
---|
115 | TEMP_FAILURE_RETRY(read(fd, iframe, s.st_size));
|
---|
116 | stillpic.iFrame = iframe;
|
---|
117 | stillpic.size = s.st_size;
|
---|
118 | #ifdef MIPSEL
|
---|
119 | int seq_end_avail = 0;
|
---|
120 | size_t pos = 0;
|
---|
121 | unsigned char pes_header[] = {0x0, 0x0, 0x1, 0xe0, 0x00, 0x00, 0x80, 0x80, 0x5, 0x21, 0x0, 0x1, 0x0, 0x1};
|
---|
122 | unsigned char seq_end[] = {0x00, 0x00, 0x01, 0xB7};
|
---|
123 | unsigned char stuffing[8192];
|
---|
124 |
|
---|
125 | memset(stuffing, 0, 8192);
|
---|
126 |
|
---|
127 | /*
|
---|
128 | if(checkchipset("3798MV200") == 1)
|
---|
129 | {
|
---|
130 | int streamtype;
|
---|
131 | if (iframe[0] == 0x00 && iframe[1] == 0x00 && iframe[2] == 0x00 && iframe[3] == 0x01 && (iframe[4] & 0x0f) == 0x07)
|
---|
132 | streamtype = VIDEO_STREAMTYPE_MPEG4_H264;
|
---|
133 | else
|
---|
134 | streamtype = VIDEO_STREAMTYPE_MPEG2;
|
---|
135 | videoselectsource(videonode, VIDEO_SOURCE_MEMORY);
|
---|
136 | videosetstreamtype(videonode, streamtype);
|
---|
137 | videosetformat(videonode, VIDEO_FORMAT_16_9);
|
---|
138 | videoplay(videonode);
|
---|
139 | videocontinue(videonode);
|
---|
140 | videoclearbuffer(videonode);
|
---|
141 | }
|
---|
142 | */
|
---|
143 | while(pos <= (s.st_size - 4) && !(seq_end_avail = (!iframe[pos] && !iframe[pos + 1] && iframe[pos + 2] == 1 && iframe[pos + 3] == 0xB7)))
|
---|
144 | ++pos;
|
---|
145 |
|
---|
146 | if((iframe[3] >> 4) != 0xE) // no pes header
|
---|
147 | write(videonode->fd, pes_header, sizeof(pes_header));
|
---|
148 | else
|
---|
149 | iframe[4] = iframe[5] = 0x00;
|
---|
150 |
|
---|
151 | write(videonode->fd, iframe, s.st_size);
|
---|
152 |
|
---|
153 | if(!seq_end_avail)
|
---|
154 | write(videonode->fd, seq_end, sizeof(seq_end));
|
---|
155 |
|
---|
156 | write(videonode->fd, stuffing, 8192);
|
---|
157 | /*
|
---|
158 | if(checkchipset("3798MV200") == 1)
|
---|
159 | addtimer(&singlepicthread, START, 1000, 1, (void*)videonode, (void*)ostrcat(filename, NULL, 0, 0), NULL);
|
---|
160 | */
|
---|
161 | #else
|
---|
162 | videoclearbuffer(videonode);
|
---|
163 | videostillpicture(videonode, &stillpic);
|
---|
164 | #endif
|
---|
165 |
|
---|
166 | free(iframe); iframe = NULL;
|
---|
167 | }
|
---|
168 | close(fd);
|
---|
169 | }
|
---|
170 | else
|
---|
171 | {
|
---|
172 | err("open %s\n", filename);
|
---|
173 | return 1;
|
---|
174 | }
|
---|
175 | printf("---end-----------------------\n");
|
---|
176 |
|
---|
177 | return 0;
|
---|
178 | }
|
---|
179 |
|
---|
180 | #endif
|
---|