Exemplo n.º 1
0
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;
	            }
	        }
        }
    }
	vbuf->last_write_jiffies64=jiffies_64;
	abuf->last_write_jiffies64=jiffies_64;
	write_size=limited_delay_check(file,vbuf,abuf,buf,count);
    if (write_size > 0) {
        return _tsdemux_write(buf, write_size);
    } else {
        return -EAGAIN;
    }
}