ssize_t esparser_write(struct file *file, struct stream_buf_s *stbuf, const char __user *buf, size_t count) { s32 r; u32 len = count; if (buf == NULL || count == 0) { return -EINVAL; } if (stbuf_space(stbuf) < count) { if (file->f_flags & O_NONBLOCK) { return -EAGAIN; } len = min(stbuf_size(stbuf) / 8, len); if (stbuf_space(stbuf) < len) { r = stbuf_wait_space(stbuf, len); if (r < 0) { return r; } } } mutex_lock(&esparser_mutex); r = _esparser_write(buf, len, stbuf->type); mutex_unlock(&esparser_mutex); return r; }
static int limited_delay_check(struct file *file, struct stream_buf_s *vbuf, struct stream_buf_s *abuf, const char __user *buf, size_t count) { int write_size; if( vbuf->max_buffer_delay_ms>0 && abuf->max_buffer_delay_ms>0 && stbuf_level(vbuf)>1024 && stbuf_level(abuf)>256){ int vdelay=calculation_stream_delayed_ms(PTS_TYPE_VIDEO,NULL,NULL); int adelay=calculation_stream_delayed_ms(PTS_TYPE_AUDIO,NULL,NULL); int maxretry=10;/*max wait 100ms,if timeout,try again top level.*/ /*too big delay,do wait now.*/ if(!(file->f_flags & O_NONBLOCK)){/*if noblock mode,don't do wait.*/ while(vdelay>vbuf->max_buffer_delay_ms && adelay>abuf->max_buffer_delay_ms && maxretry-->0){ ///printk("too big delay,vdelay:%d>%d adelay:%d>%d,do wait now,retry=%d\n",vdelay,vbuf->max_buffer_delay_ms,adelay,abuf->max_buffer_delay_ms,maxretry); msleep(10); vdelay=calculation_stream_delayed_ms(PTS_TYPE_VIDEO,NULL,NULL); adelay=calculation_stream_delayed_ms(PTS_TYPE_AUDIO,NULL,NULL); } } if(vdelay>vbuf->max_buffer_delay_ms && adelay>abuf->max_buffer_delay_ms) return 0; } write_size = min(stbuf_space(vbuf), stbuf_space(abuf)); write_size = min((int)count, write_size); return write_size; }
ssize_t esparser_write(struct file *file, struct stream_buf_s *stbuf, const char __user *buf, size_t count) { s32 r; u32 len = count; if (buf == NULL || count == 0) { return -EINVAL; } if (stbuf->type!=BUF_TYPE_SUBTITLE && /*subtitle have no level to check,*/ stbuf_space(stbuf) < count) { if (file->f_flags & O_NONBLOCK) { len = stbuf_space(stbuf) ; if(len<256)//<1k.do eagain, return -EAGAIN; }else{ len = min(stbuf_canusesize(stbuf) / 8, len); if (stbuf_space(stbuf) < len) { r = stbuf_wait_space(stbuf, len); if (r < 0) { return r; } } } } len = min(len, count); mutex_lock(&esparser_mutex); r = _esparser_write(buf, len, stbuf->type); mutex_unlock(&esparser_mutex); return r; }
ssize_t tsdemux_write(struct file *file, struct stream_buf_s *vbuf, struct stream_buf_s *abuf, const char __user *buf, size_t count) { s32 r; stream_port_t *port = (stream_port_t *)file->private_data; size_t wait_size, write_size; if ((stbuf_space(vbuf) < count) || (stbuf_space(abuf) < count)) { if (file->f_flags & O_NONBLOCK) { write_size=min(stbuf_space(vbuf), stbuf_space(abuf)); if(write_size<=188)/*have 188 bytes,write now., */ return -EAGAIN; }else{ wait_size = min(stbuf_canusesize(vbuf) / 8, stbuf_canusesize(abuf) / 4); if ((port->flag & PORT_FLAG_VID) && (stbuf_space(vbuf) < wait_size)) { r = stbuf_wait_space(vbuf, wait_size); if (r < 0) { printk("write no space--- no space,%d--%d,r-%d\n",stbuf_space(vbuf),stbuf_space(abuf),r); return r; } } if ((port->flag & PORT_FLAG_AID) && (stbuf_space(abuf) < wait_size)) { r = stbuf_wait_space(abuf, wait_size); if (r < 0) { printk("write no stbuf_wait_space--- no space,%d--%d,r-%d\n",stbuf_space(vbuf),stbuf_space(abuf),r); return r; } } } } write_size=limited_delay_check(file,vbuf,abuf,buf,count); if (write_size > 0) { return _tsdemux_write(buf, write_size); } else { return -EAGAIN; } }
ssize_t rmparser_write(struct file *file, struct stream_buf_s *vbuf, struct stream_buf_s *abuf, const char __user *buf, size_t count) { s32 r; stream_port_t *port = (stream_port_t *)file->private_data; size_t towrite=count; if ((stbuf_space(vbuf) < count) || (stbuf_space(abuf) < count)) { if (file->f_flags & O_NONBLOCK) { towrite=min(stbuf_space(vbuf), stbuf_space(abuf)); if(towrite<1024)/*? can write small?*/ return -EAGAIN; }else{ if ((port->flag & PORT_FLAG_VID) && (stbuf_space(vbuf) < count)) { r = stbuf_wait_space(vbuf, count); if (r < 0) { return r; } } if ((port->flag & PORT_FLAG_AID) && (stbuf_space(abuf) < count)) { r = stbuf_wait_space(abuf, count); if (r < 0) { return r; } } } } towrite=min(towrite,count); return _rmparser_write(buf, towrite); }
static void _stbuf_timer_func(unsigned long arg) { struct stream_buf_s *p = (struct stream_buf_s *)arg; if (stbuf_space(p) < p->wcnt) { p->timer.expires = jiffies + STBUF_WAIT_INTERVAL; add_timer(&p->timer); } else { wake_up_interruptible(&p->wq); } }
s32 stbuf_wait_space(struct stream_buf_s *stream_buf, size_t count) { stream_buf_t *p = stream_buf; long time_out = 20; p->wcnt = count; setup_timer(&p->timer, _stbuf_timer_func, (ulong)p); mod_timer(&p->timer, jiffies + STBUF_WAIT_INTERVAL); if (wait_event_interruptible_timeout(p->wq, stbuf_space(p) >= count, time_out) == 0) { del_timer_sync(&p->timer); return -EAGAIN; } del_timer_sync(&p->timer); return 0; }
ssize_t drm_write(struct file *file, struct stream_buf_s *stbuf, const char __user *buf, size_t count) { s32 r; u32 len ; u32 realcount,totalcount; u32 re_count = count; u32 havewritebytes =0; u32 leftcount = 0; drminfo_t tmpmm; drminfo_t *drm=&tmpmm; u32 res=0; int isphybuf=0; if (buf == NULL || count == 0) { return -EINVAL; } res = copy_from_user(drm, buf, sizeof(drminfo_t)); if (res) { printk("drm kmalloc failed res[%d]\n",res); return -EFAULT; } if (drm->drm_flag == TYPE_DRMINFO && (drm->drm_hasesdata == 0)) { realcount = drm->drm_pktsize; //buf only has drminfo not have esdata; buf = (char *)drm->drm_phy; isphybuf =1; //DRM_PRNT("drm_get_rawdata onlydrminfo drm->drm_hasesdata[0x%x] stbuf->type %d buf[0x%x]\n",drm->drm_hasesdata,stbuf->type,buf); } else if (drm->drm_hasesdata == 1) {//buf is drminfo+es; realcount = drm->drm_pktsize; buf = buf + sizeof(drminfo_t); isphybuf =0; //DRM_PRNT("drm_get_rawdata drminfo+es drm->drm_hasesdata[0x%x] stbuf->type %d\n",drm->drm_hasesdata,stbuf->type); } else {//buf is hwhead; realcount = count; isphybuf =0; //DRM_PRNT("drm_get_rawdata drm->drm_hasesdata[0x%x] len[%d] count[%d] realcout[%d]\n",drm->drm_hasesdata,len,count,realcount); } len = realcount ; count = realcount; totalcount = realcount; while (len > 0) { if (stbuf->type!=BUF_TYPE_SUBTITLE && stbuf_space(stbuf) < count) { len = min(stbuf_canusesize(stbuf) / 8, len); if (stbuf_space(stbuf) < len) { r = stbuf_wait_space(stbuf, len); if ((r < leftcount) && (leftcount > 0)) { // write part data , not allow return ; continue; }else if ((r < 0)&&(leftcount==0)){//buf is full; return -EAGAIN; } } } len = min(len, count); mutex_lock(&esparser_mutex); r = _esparser_write(buf,len,stbuf->type,isphybuf); if (r < 0){ printk("drm_write _esparser_write failed [%d]\n",r); return r; } havewritebytes += r; leftcount = totalcount - havewritebytes; if (havewritebytes == totalcount){ mutex_unlock(&esparser_mutex); break;//write ok; }else if ((len > 0 )&& (havewritebytes < totalcount)){ DRM_PRNT("writeagain havewritebytes[%d] wantwrite[%d] totalcount[%d] realcount[%d] \n", havewritebytes,len,totalcount,realcount); len = len-r;//write again; buf=buf+r; }else{ printk("###else havewritebytes[%d] wantwrite[%d] totalcount[%d] realcount[%d]\n", havewritebytes,len,totalcount,realcount); } mutex_unlock(&esparser_mutex); } return re_count; }