Changeset 44973


Ignore:
Timestamp:
12/08/20 21:06:13 (3 years ago)
Author:
obi
Message:

fix

Location:
titan/libeplayer3/output/writer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • titan/libeplayer3/output/writer/common/writer.c

    r44970 r44973  
    2626#include <string.h>
    2727#include <errno.h>
    28 #include <pthread.h>
    2928
    3029#include "misc.h"
    3130#include "writer.h"
     31#include "debug.h"
    3232#include "common.h"
    33 #include "debug.h"
    3433
    3534/* ***************************** */
    3635/* Makros/Constants              */
    3736/* ***************************** */
    38 #define getDVBMutex(pmtx) do { if (pmtx) pthread_mutex_lock(pmtx);} while(false);
    39 #define releaseDVBMutex(pmtx) do { if (pmtx) pthread_mutex_unlock(pmtx);} while(false);
    4037
    4138/* ***************************** */
    4239/* Types                         */
    4340/* ***************************** */
    44 typedef enum {
    45     DVB_STS_UNKNOWN,
    46     DVB_STS_SEEK,
    47     DVB_STS_PAUSE,
    48     DVB_STS_EXIT
    49 } DVBState_t;
    5041
    5142/* ***************************** */
    5243/* Varaibles                     */
    5344/* ***************************** */
    54 
    55 static Writer_t * AvailableWriter[] = {
    56     &WriterAudioAAC,
    57     &WriterAudioAACLATM,
    58     &WriterAudioAACPLUS,
    59     &WriterAudioAC3,
    60     &WriterAudioEAC3,
    61     &WriterAudioMP3,
    62     &WriterAudioMPEGL3,
    63     &WriterAudioPCM,
    64     &WriterAudioIPCM,
    65     &WriterAudioLPCM,
    66     &WriterAudioDTS,
    67     &WriterAudioWMA,
    68     &WriterAudioWMAPRO,
    69     &WriterAudioOPUS,
    70     &WriterAudioVORBIS,
    71 
    72     &WriterVideoH264,
    73     &WriterVideoH265,
    74     &WriterVideoH263,
    75     &WriterVideoMPEG4,
    76     &WriterVideoMPEG2,
    77     &WriterVideoMPEG1,
    78     &WriterVideoVC1,
    79     &WriterVideoDIVX3,
    80     &WriterVideoVP6,
    81     &WriterVideoVP8,
    82     &WriterVideoVP9,
    83     &WriterVideoFLV,
    84     &WriterVideoWMV,
    85     &WriterVideoMJPEG,
    86     &WriterVideoRV40,
    87     &WriterVideoRV30,
    88     &WriterVideoAVS2,
    89     NULL
    90 };
    9145
    9246/* ***************************** */
     
    9751/*  Functions                    */
    9852/* ***************************** */
    99 ssize_t WriteWithRetry(Context_t *context, int pipefd, int fd, void *pDVBMtx, const void *buf, int size)
     53void FlushPipe(int pipefd)
    10054{
    101     fd_set rfds;
    102     fd_set wfds;
    103 
    104     ssize_t ret;
    105     int retval = -1;
    106     int maxFd = pipefd > fd ? pipefd : fd;
    107     struct timeval tv;
    108 
    109 //    while(size > 0 && !context->playback->isSeeking)
    110     while(size > 0 && 0 == PlaybackDieNow(0) && !context->playback->isSeeking)
    111     {
    112         FD_ZERO(&rfds);
    113         FD_ZERO(&wfds);
    114 
    115         FD_SET(pipefd, &rfds);
    116         FD_SET(fd, &wfds);
    117 
    118         /* When we PAUSE LINUX DVB outputs buffers, then audio/video buffers
    119          * will continue to be filled. Unfortunately, in such case after resume
    120          * select() will never return with fd set - bug in DVB drivers?
    121          * There are to workarounds possible:
    122          *   1. write to pipe at resume to return from select() immediately
    123          *   2. make timeout select(), limit max time spend in the select()
    124          *      to for example 0,1s
    125          *   (at now first workaround is used)
    126          */
    127         //tv.tv_sec = 0;
    128         //tv.tv_usec = 100000; // 100ms
    129        
    130         retval = select(maxFd + 1, &rfds, &wfds, NULL, NULL); //&tv);
    131         if (retval < 0)
    132         {
    133             break;
    134         }
    135        
    136         //if (retval == 0)
    137         //{
    138         //    //printf("RETURN FROM SELECT DUE TO TIMEOUT\n");
    139         //    continue;
    140         //}
    141        
    142         if(FD_ISSET(pipefd, &rfds))
    143         {
    144             FlushPipe(pipefd);
    145             //printf("RETURN FROM SELECT DUE TO pipefd SET\n");
    146             continue;
    147         }
    148        
    149         if(FD_ISSET(fd, &wfds))
    150         {
    151             ret = write(fd, buf, size);
    152             if (ret < 0)
    153             {
    154                 switch(errno)
    155                 {
    156                     case EINTR:
    157                     case EAGAIN:
    158                         continue;
    159                     default:
    160                         retval = -3;
    161                         break;
    162                 }
    163                 if (retval < 0)
    164                 {
    165                     break;
    166                 }
    167                
    168                 return ret;
    169             }
    170             else if (ret == 0)
    171             {
    172                 // printf("This should not happen. Select return fd ready to write, but write return 0, errno [%d]\n", errno);
    173                 // wait 10ms before next try
    174                 tv.tv_sec = 0;
    175                 tv.tv_usec = 10000; // 10ms
    176                 retval = select(pipefd + 1, &rfds, NULL, NULL, &tv);
    177                 if (retval)
    178                     FlushPipe(pipefd);
    179                 continue;
    180             }
    181            
    182             size -= ret;
    183             buf += ret;
    184         }
    185     }
    186     return 0;
     55    char tmp;
     56    while(1 == read(pipefd, &tmp, 1));
    18757}
    18858
    189 ssize_t write_with_retry(int fd, const void *buf, int size)
     59ssize_t WriteExt(WriteV_t _call, int fd, void *data, size_t size)
    19060{
    191     ssize_t ret;
    192     int retval = 0;
    193 //    while(size > 0 && 0 == PlaybackDieNow(0))
    194     while(size > 0)
    195     {
    196         ret = write(fd, buf, size);
    197         if (ret < 0)
    198         {
    199             switch(errno)
    200             {
    201                 case EINTR:
    202                 case EAGAIN:
    203                     usleep(1000);
    204                     continue;
    205                 default:
    206                     retval = -3;
    207                     break;
    208             }
    209             if (retval < 0)
    210             {
    211                 break;
    212             }
    213         }
    214            
    215         if (ret < 0)
    216         {
    217             return ret;
    218         }
    219        
    220         size -= ret;
    221         buf += ret;
    222        
    223         if(size > 0)
    224         {
    225             if( usleep(1000) )
    226             {
    227                 writer_err("usleep error \n");
    228             }
    229         }
    230     }
    231     return 0;
     61    struct iovec iov[1];
     62    iov[0].iov_base = data;
     63    iov[0].iov_len = size;
     64    return _call(fd, iov, 1);
    23265}
    233 
    234 ssize_t writev_with_retry(int fd, const struct iovec *iov, int ic)
    235 {
    236     ssize_t len = 0;
    237     int i = 0;
    238     for(i=0; i<ic; ++i)
    239     {
    240         write_with_retry(fd, iov[i].iov_base, iov[i].iov_len);
    241         len += iov[i].iov_len;
    242         if(PlaybackDieNow(0))
    243         {
    244 //            return -1;
    245         }
    246     }
    247     return len;
    248 }
    249 
    250 Writer_t* getWriter(char* encoding)
    251 {
    252     int i;
    253 
    254     for (i = 0; AvailableWriter[i] != NULL; i++)
    255     {
    256         if (strcmp(AvailableWriter[i]->caps->textEncoding, encoding) == 0)
    257         {
    258             writer_printf(50, "%s: found writer \"%s\" for \"%s\"\n", __func__, AvailableWriter[i]->caps->name, encoding);
    259             return AvailableWriter[i];
    260         }
    261     }
    262 
    263     writer_printf(1, "%s: no writer found for \"%s\"\n", __func__, encoding);
    264 
    265     return NULL;
    266 }
    267 
    268 Writer_t* getDefaultVideoWriter()
    269 {
    270     int i;
    271 
    272     for (i = 0; AvailableWriter[i] != NULL; i++)
    273     {
    274         if (strcmp(AvailableWriter[i]->caps->textEncoding, "V_MPEG2") == 0)
    275         {
    276             writer_printf(50, "%s: found writer \"%s\"\n", __func__, AvailableWriter[i]->caps->name);
    277             return AvailableWriter[i];
    278         }
    279     }
    280 
    281     writer_printf(1, "%s: no writer found\n", __func__);
    282 
    283     return NULL;
    284 }
    285 
    286 Writer_t* getDefaultAudioWriter()
    287 {
    288     int i;
    289 
    290     for (i = 0; AvailableWriter[i] != NULL; i++)
    291     {
    292         if (strcmp(AvailableWriter[i]->caps->textEncoding, "A_MP3") == 0)
    293         {
    294             writer_printf(50, "%s: found writer \"%s\"\n", __func__, AvailableWriter[i]->caps->name);
    295             return AvailableWriter[i];
    296         }
    297     }
    298 
    299     writer_printf(1, "%s: no writer found\n", __func__);
    300 
    301     return NULL;
    302 }
    303 
  • titan/libeplayer3/output/writer/mipsel/writer.c

    r44958 r44973  
    107107    struct timeval tv;
    108108
     109//    while(size > 0 && !context->playback->isSeeking)
    109110    while(size > 0 && 0 == PlaybackDieNow(0) && !context->playback->isSeeking)
    110111    {
     
    190191    ssize_t ret;
    191192    int retval = 0;
    192     while(size > 0 && 0 == PlaybackDieNow(0))
     193//    while(size > 0 && 0 == PlaybackDieNow(0))
     194    while(size > 0)
    193195    {
    194196        ret = write(fd, buf, size);
     
    240242        if(PlaybackDieNow(0))
    241243        {
    242             return -1;
     244//            return -1;
    243245        }
    244246    }
Note: See TracChangeset for help on using the changeset viewer.