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;
}
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;
}
Exemple #3
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;
}