public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Antti Palosaari <crope@iki.fi>
To: Hans Verkuil <hverkuil@xs4all.nl>, linux-media@vger.kernel.org
Subject: Re: [PATCHv2 8/9] hackrf: add support for transmitter
Date: Wed, 29 Jul 2015 02:04:39 +0300	[thread overview]
Message-ID: <55B80A87.6090206@iki.fi> (raw)
In-Reply-To: <55B729E4.1070501@xs4all.nl>

On 07/28/2015 10:06 AM, Hans Verkuil wrote:
> On 07/28/2015 02:50 AM, Antti Palosaari wrote:
>> On 07/27/2015 11:38 PM, Hans Verkuil wrote:
>>> On 07/27/2015 10:21 PM, Antti Palosaari wrote:
>>>> On 07/17/2015 05:43 PM, Hans Verkuil wrote:
>>>>> On 07/16/2015 09:04 AM, Antti Palosaari wrote:
>>>>>> HackRF SDR device has both receiver and transmitter. There is limitation
>>>>>> that receiver and transmitter cannot be used at the same time
>>>>>> (half-duplex operation). That patch implements transmitter support to
>>>>>> existing receiver only driver.
>>>>>>
>>>>>> Cc: Hans Verkuil <hverkuil@xs4all.nl>
>>>>>> Signed-off-by: Antti Palosaari <crope@iki.fi>
>>>>>> ---
>>>>>>     drivers/media/usb/hackrf/hackrf.c | 787 +++++++++++++++++++++++++++-----------
>>>>>>     1 file changed, 572 insertions(+), 215 deletions(-)
>>>>>>
>>>>>
>>>>>
>>>>>> @@ -611,8 +751,15 @@ static int hackrf_queue_setup(struct vb2_queue *vq,
>>>>>>     		unsigned int *nplanes, unsigned int sizes[], void *alloc_ctxs[])
>>>>>>     {
>>>>>>     	struct hackrf_dev *dev = vb2_get_drv_priv(vq);
>>>>>> +	struct usb_interface *intf = dev->intf;
>>>>>> +	int ret;
>>>>>>
>>>>>> -	dev_dbg(dev->dev, "nbuffers=%d\n", *nbuffers);
>>>>>> +	dev_dbg(&intf->dev, "nbuffers=%d\n", *nbuffers);
>>>>>> +
>>>>>> +	if (test_and_set_bit(QUEUE_SETUP, &dev->flags)) {
>>>>>> +		ret = -EBUSY;
>>>>>> +		goto err;
>>>>>> +	}
>>>>>
>>>>> This doesn't work. The bit is only cleared when start_streaming fails or
>>>>> stop_streaming is called. But the application can also call REQBUFS again
>>>>> or just close the file handle, and then QUEUE_SETUP should also be cleared.
>>>>>
>>>>> But why is this here in the first place? It doesn't seem to do anything
>>>>> useful (except mess up the v4l2-compliance tests).
>>>>>
>>>>> I've removed it and it now seems to work OK.
>>>>
>>>> It is there to block simultaneous use of receiver and transmitter.
>>>> Device could operate only single mode at the time - receiving or
>>>> transmitting. Driver shares streaming buffers.
>>>>
>>>> Any idea how I can easily implement correct blocking?
>>>
>>> Since each video_device struct has its own vb2_queue I wouldn't put the check
>>> here. Instead, put the check in the start_streaming callback. And the check
>>> is easy enough: if you want to start capturing, then call
>>> vb2_is_streaming(&tx_vb2_queue). If you want to start output, then call
>>> vb2_is_streaming(&rx_vb2_queue). If the other 'side' is streaming, then
>>> return EBUSY.
>>>
>>> It's perfectly valid to allocate the buffers, but actually streaming is an
>>> exclusive operation.
>>
>> Currently there is two queues, but only single buffer. If I do check on
>> start_streaming() it is too late as buffers are queue during buf_queue()
>> which is called earlier (and now both sides are added to same
>> queued_bufs lists, which messes up).
>
> It's not that you have a single buffer, it is that you have a single buffer list.
> I'd say that you should make two buffer lists and use the appropriate one. They
> really are independent, it's just that VIDIOC_STREAMON can run only one queue
> at a time.

I have done too looong day about that dual buffer list implementation. 
There is some very strange behavior, which makes it almost impossible. 
If I try return receiver buffers with status VB2_BUF_STATE_QUEUED and 
EBUSY from start_streaming() it does not stop, but starts wildly calling 
buf_queue() in a endless loop eating all the CPU and so. For transmitter 
it seems to work as I expected.

You could repeat that same issue using vivid:
# modprobe vivid
# v4l2-ctl -d /dev/video0 -C inject_vidioc_streamon_error
# cat /dev/video0 > /dev/null

and it does not stop with ctrl-C

regards
Antti

-- 
http://palosaari.fi/

  reply	other threads:[~2015-07-28 23:04 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-16  7:04 [PATCHv2 0/9] SDR transmitter API Antti Palosaari
2015-07-16  7:04 ` [PATCHv2 1/9] v4l2: rename V4L2_TUNER_ADC to V4L2_TUNER_SDR Antti Palosaari
2015-07-17 14:32   ` Hans Verkuil
2015-07-16  7:04 ` [PATCHv2 2/9] v4l2: add RF gain control Antti Palosaari
2015-07-16  7:04 ` [PATCHv2 3/9] DocBook: document tuner " Antti Palosaari
2015-07-16  7:04 ` [PATCHv2 4/9] v4l2: add support for SDR transmitter Antti Palosaari
2015-07-16  7:04 ` [PATCHv2 5/9] DocBook: document " Antti Palosaari
2015-07-16  7:04 ` [PATCHv2 6/9] hackrf: add control for RF amplifier Antti Palosaari
2015-07-16  7:04 ` [PATCHv2 7/9] hackrf: switch to single function which configures everything Antti Palosaari
2015-07-16  7:04 ` [PATCHv2 8/9] hackrf: add support for transmitter Antti Palosaari
2015-07-17 13:04   ` Hans Verkuil
2015-07-17 14:15   ` Hans Verkuil
2015-07-27 16:19     ` Antti Palosaari
2015-07-27 17:19       ` Hans Verkuil
2015-07-17 14:43   ` Hans Verkuil
2015-07-27 20:21     ` Antti Palosaari
2015-07-27 20:38       ` Hans Verkuil
2015-07-28  0:50         ` Antti Palosaari
2015-07-28  7:06           ` Hans Verkuil
2015-07-28 23:04             ` Antti Palosaari [this message]
2015-07-16  7:04 ` [PATCHv2 9/9] hackrf: do not set human readable name for formats Antti Palosaari
2015-07-17 14:46 ` [PATCHv2 0/9] SDR transmitter API Hans Verkuil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55B80A87.6090206@iki.fi \
    --to=crope@iki.fi \
    --cc=hverkuil@xs4all.nl \
    --cc=linux-media@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox