source: titan/libeplayer3/output/writer/mipsel/writer.c @ 42431

Last change on this file since 42431 was 42431, checked in by obi, 6 years ago

reset libeplayer

File size: 5.2 KB
Line 
1/*
2 * linuxdvb output/writer handling.
3 *
4 * konfetti 2010
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22/* ***************************** */
23/* Includes                      */
24/* ***************************** */
25#include <stdlib.h>
26#include <string.h>
27#include <errno.h>
28
29#include "misc.h"
30#include "writer.h"
31
32/* ***************************** */
33/* Makros/Constants              */
34/* ***************************** */
35
36#define WRITER_DEBUG
37
38#ifdef WRITER_DEBUG
39
40static short debug_level = 0;
41
42#define writer_printf(level, x...) do { \
43if (debug_level >= level) printf(x); } while (0)
44#else
45#define writer_printf(level, x...)
46#endif
47
48#ifndef WRITER_SILENT
49#define writer_err(x...) do { printf(x); } while (0)
50#else
51#define writer_err(x...)
52#endif
53
54/* ***************************** */
55/* Types                         */
56/* ***************************** */
57
58/* ***************************** */
59/* Varaibles                     */
60/* ***************************** */
61
62static Writer_t * AvailableWriter[] = {
63    &WriterAudioAAC,
64    &WriterAudioAACLATM,
65    &WriterAudioAACPLUS,
66    &WriterAudioAC3,
67    &WriterAudioEAC3,
68    &WriterAudioMP3,
69    &WriterAudioMPEGL3,
70    &WriterAudioPCM,
71    &WriterAudioIPCM,
72    &WriterAudioLPCM,
73    &WriterAudioDTS,
74    &WriterAudioWMA,
75    &WriterAudioWMAPRO,
76   
77    &WriterVideoH264,
78    &WriterVideoH265,
79    &WriterVideoH263,
80    &WriterVideoMPEG4,
81    &WriterVideoMPEG2,
82    &WriterVideoMPEG1,
83    &WriterVideoVC1,
84    &WriterVideoDIVX3,
85    &WriterVideoVP6,
86    &WriterVideoVP8,
87    &WriterVideoVP9,
88    &WriterVideoSPARK,
89    &WriterVideoWMV,
90    NULL
91};
92
93/* ***************************** */
94/* Prototypes                    */
95/* ***************************** */
96
97/* ***************************** */
98/*  Functions                    */
99/* ***************************** */
100ssize_t write_with_retry(int fd, const void *buf, size_t size)
101{
102    ssize_t ret;
103    int retval = 0;
104//obi
105//    while(size > 0 && 0 == PlaybackDieNow(0))
106    while(size > 0)
107//obi (end)
108    {
109        ret = write(fd, buf, size);
110        //printf("[%d] write [%lld]\n", fd, ret);
111        if (ret < 0)
112        {
113            switch(errno)
114            {
115                case EINTR:
116                case EAGAIN:
117                    usleep(1000);
118                    continue;
119                default:
120                    retval = -3;
121                    break;
122            }
123            if (retval < 0)
124            {
125                break;
126            }
127        }
128           
129        if (ret < 0)
130        {
131            return ret;
132        }
133       
134        size -= ret;
135        buf += ret;
136       
137        if(size > 0)
138        {
139            if( usleep(1000) )
140            {
141                writer_err("usleep error \n");
142            }
143        }
144    }
145    return 0;
146}
147
148ssize_t writev_with_retry(int fd, const struct iovec *iov, size_t ic)
149{
150    ssize_t len = 0;
151    int i = 0;
152    for(i=0; i<ic; ++i)
153    {
154        write_with_retry(fd, iov[i].iov_base, iov[i].iov_len);
155        len += iov[i].iov_len;
156        if(PlaybackDieNow(0))
157        {
158//obi
159//            return -1;
160//obi (end)
161        }
162    }
163    return len;
164}
165
166Writer_t* getWriter(char* encoding)
167{
168    int i;
169
170    for (i = 0; AvailableWriter[i] != NULL; i++)
171    {
172        if (strcmp(AvailableWriter[i]->caps->textEncoding, encoding) == 0)
173        {
174            writer_printf(50, "%s: found writer \"%s\" for \"%s\"\n", __func__, AvailableWriter[i]->caps->name, encoding);
175            return AvailableWriter[i];
176        }
177    }
178
179    writer_printf(1, "%s: no writer found for \"%s\"\n", __func__, encoding);
180
181    return NULL;
182}
183
184Writer_t* getDefaultVideoWriter()
185{
186    int i;
187
188    for (i = 0; AvailableWriter[i] != NULL; i++)
189    {
190        if (strcmp(AvailableWriter[i]->caps->textEncoding, "V_MPEG2") == 0)
191        {
192            writer_printf(50, "%s: found writer \"%s\"\n", __func__, AvailableWriter[i]->caps->name);
193            return AvailableWriter[i];
194        }
195    }
196
197    writer_printf(1, "%s: no writer found\n", __func__);
198
199    return NULL;
200}
201
202Writer_t* getDefaultAudioWriter()
203{
204    int i;
205
206    for (i = 0; AvailableWriter[i] != NULL; i++)
207    {
208        if (strcmp(AvailableWriter[i]->caps->textEncoding, "A_MP3") == 0)
209        {
210            writer_printf(50, "%s: found writer \"%s\"\n", __func__, AvailableWriter[i]->caps->name);
211            return AvailableWriter[i];
212        }
213    }
214
215    writer_printf(1, "%s: no writer found\n", __func__);
216
217    return NULL;
218}
219
Note: See TracBrowser for help on using the repository browser.