All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shuah Khan <shuahkh@osg.samsung.com>
To: Takashi Iwai <tiwai@suse.de>, Hans Verkuil <hverkuil@xs4all.nl>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
	m.chehab@samsung.com, akpm@linux-foundation.org,
	gregkh@linuxfoundation.org, crope@iki.fi, olebowle@gmx.com,
	dheitmueller@kernellabs.com, ramakrmu@cisco.com,
	sakari.ailus@linux.intel.com, laurent.pinchart@ideasonboard.com,
	perex@perex.cz, prabhakar.csengg@gmail.com,
	tim.gardner@canonical.com, linux@eikelenboom.it,
	linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org,
	linux-media@vger.kernel.org
Subject: Re: [alsa-devel] [PATCH v2 5/6] sound/usb: pcm changes to use media token api
Date: Tue, 21 Oct 2014 11:32:10 -0600	[thread overview]
Message-ID: <5446989A.3010000@osg.samsung.com> (raw)
In-Reply-To: <s5hbnp5z9uy.wl-tiwai@suse.de>

On 10/21/2014 10:05 AM, Takashi Iwai wrote:
> At Tue, 21 Oct 2014 17:42:51 +0200,
> Hans Verkuil wrote:

>>
>> Quite often media apps open the alsa device at the start and then switch
>> between TV, radio or DVB mode. If the alsa device would claim the tuner
>> just by being opened (as opposed to actually using the tuner, which happens
>> when you start streaming),
> 
> What about parameter changes?  The sound devices have to be configured
> before using.  Don't they influence on others at all, i.e. you can
> change the PCM sample rate etc during TV, radio or DVB is running?

Yes. kaffeine uses  snd_usb_capture_ops ioctl -> snd_pcm_lib_ioctl

Other v4l and vlc (dvb) uses open/close as well as trigger start and
stop. trigger start/stop is done by a special audio thread in some
cases. open/close happens from the main thread.

> 
>> then that would make it impossible for the
>> application to switch tuner mode. In general you want to avoid that open()
>> will start configuring hardware since that can quite often be slow. Tuner
>> configuration in particular can be slow since several common tuners need
>> to load firmware over i2c. You only want to do that when it is really needed,
>> and not when some application (udev!) opens the device just to examine what
>> sort of device it is.
> 
> But most apps close the device soon after that, no?
> Which programs keep the PCM device (not the control) opened without
> actually using?
> 
>> So claiming the tuner in the trigger seems to be the right place. If
>> returning EBUSY is a poor error code for alsa, then we can use something else
>> for that. EACCES perhaps?
> 
> Sorry, I'm not convinced by that.  If the device has to be controlled
> exclusively, the right position is the open/close.  Otherwise, the
> program cannot know when it becomes inaccessible out of sudden during
> its operation.
> 
> 

Let me share my test matrix for this patch series. Hans pointed out
one test case I didn't know about as a result missed testing. Please
see if any of the tests miss use-cases or break them: you can scroll
down to the proposal at the end, if this is too much detail :)

Digital active and analog starting testing:
kaffeine running
- v4l2-ctl --all - works
- Changing channels works with the same token hold, even when
  frequency changes. Tested changing channels that force freq
  change.
- vlc resource is busy with no disruption to kaffeine
- xawtv - tuner busy when it tries to do ioctls that change
  tuner settings - snd_usb_pcm_open detects device is busy
  ( pcm open called from the same thread, trigger gets called
    from another thread )
- tvtime - tuner busy when it tries to do ioctls that change
  tuner settings with no disruption to kaffeine
  ( pcm open called from the same thread, trigger gets called
    from another thread )
- vlc - audio capture on WinTV HVR-950 - device is busy
  start vlc with no channels for this test
- arecord to capture on WinTV HVR-950 - device busy

vlc running
vlc -v channels.xspf
- v4l2-ctl --all - works
- Changing channels works with the same token hold, even when
  frequency changes. Tested changing channels that force freq
  change.
- kaffeine resource is busy with no disruption to vlc
- xawtv - tuner busy when it tries to do ioctls that change
  tuner settings - snd_usb_pcm_open detects device is busy
  ( pcm open called from the same thread, trigger gets called
    from another thread )
- tvtime - tuner busy when it tries to do ioctls that change
  tuner settings with no disruption to kaffeine
  ( pcm open called from the same thread, trigger gets called
    from another thread )
- vlc - audio capture on WinTV HVR-950 - device is busy
- arecord to capture on WinTV HVR-950 - device busy

Analog active and start digital testing:
xawtv -noalsa -c /dev/video1
- v4l2-ctl --all - works
- start kaffeine - fails with device busy and no disruption
- start vlc - fails with device busy and no disruption
- tvtime - tuner busy when it tries to do ioctls that change
  tuner settings with no disruption to kaffeine
- vlc - audio capture on WinTV HVR-950 - device is busy
- arecord to capture on WinTV HVR-950 - device busy

tvtime
- v4l2-ctl --all - works
- start kaffeine - fails with device busy and no disruption
- start vlc - fails with device busy and no disruption
- xawtv - tuner busy when it tries to do ioctls that change
  tuner settings with no disruption to kaffeine
- vlc - audio capture on WinTV HVR-950 - device is busy
- arecord to capture on WinTV HVR-950 - device busy

The following audio/video start/stop combination tests:
( used arecord as well to test these cases, arecord )

- tvtime start/vlc start/vlc stop/tvtime stop
  no disruption to tvtime
- tvtime start/vlc start/tvtie stop/vlc stop
  One tvtime stops, could trigger capture manually
- vlc start/tvtime start/tvtime stop/vlc stop
  vlc audio capture continues, tvtime detect tuner busy
- vlc start/tvtime start/vlc stop/tvtime start
  when vlc stops, tvtime could open the tuner device

Repeated the above with kaffeine and vlc and arecord audio
capture combinations.

Hans pointed out I am missing:

v4l2-ctl -f 180 --sleep=10
While it is sleeping you must still be able to set the frequency from
another console.

And it doesn't matter which of the two v4l2-ctl processes ends first,
as long as one has a reference to the tuner you should be blocked
from switching the tuner to a different mode (radio or dvb)

I think this above fails because tuner token ownership doesn't
span processes. Token should act as a lock between dvb/audio/v4l,
and v4l itself has mechanisms to handle the multiple ownership token
shouldn't interfere with.

Provided the only thing that is breaking is the v4l case, I think
I can get it to work with the bit field approach.

Here is what I propose for patch v3:
- make it a module under media
- collapse tuner and audio tokens into media token
- change names (get rid of abbreviated tkn stuff)
- Make other changes Takashi/Lars pointed out in pcm
- hold token in pcm open/close
- add a bitfield to struct v4l2_fh to handle
  the v4l specific multiple ownership cases.
- v4l-core and au0828-videp patches will see changes.
- dvb patch should still be good (crossing fingers)

thanks,
-- Shuah

-- 
Shuah Khan
Sr. Linux Kernel Developer
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978

  parent reply	other threads:[~2014-10-21 17:32 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-14 14:58 [PATCH v2 0/6] media token resource framework Shuah Khan
2014-10-14 14:58 ` [PATCH v2 1/6] media: add media token device " Shuah Khan
2014-10-15 17:05   ` Takashi Iwai
2014-10-16  0:53     ` Shuah Khan
2014-10-16 14:00       ` Takashi Iwai
2014-10-16 14:39         ` Shuah Khan
2014-10-21 10:46   ` Hans Verkuil
2014-10-21 11:51     ` Takashi Iwai
2014-10-21 11:58       ` Hans Verkuil
2014-10-21 13:07         ` Takashi Iwai
2014-11-18 21:33   ` Sakari Ailus
2014-10-14 14:58 ` [PATCH v2 2/6] media: v4l2-core changes to use media token api Shuah Khan
2014-10-14 14:58 ` [PATCH v2 3/6] media: au0828-video " Shuah Khan
2014-10-14 14:58 ` [PATCH v2 4/6] media: dvb-core " Shuah Khan
2014-10-14 14:58 ` [PATCH v2 5/6] sound/usb: pcm " Shuah Khan
2014-10-16 12:00   ` Lars-Peter Clausen
2014-10-16 12:00     ` [alsa-devel] " Lars-Peter Clausen
2014-10-16 13:10     ` Shuah Khan
2014-10-16 14:01       ` Takashi Iwai
2014-10-16 14:10         ` Shuah Khan
2014-10-16 14:16           ` Takashi Iwai
2014-10-16 14:39             ` Shuah Khan
2014-10-16 14:48               ` Takashi Iwai
2014-10-16 14:59                 ` Shuah Khan
2014-10-16 14:59                   ` [alsa-devel] " Shuah Khan
2014-10-18 18:49                   ` Mauro Carvalho Chehab
2014-10-19  9:00                     ` Takashi Iwai
2014-10-19  9:00                       ` [alsa-devel] " Takashi Iwai
2014-10-21 15:42                 ` Hans Verkuil
2014-10-21 16:05                   ` Takashi Iwai
2014-10-21 16:08                     ` Devin Heitmueller
2014-10-21 16:14                       ` Takashi Iwai
2014-10-22 19:26                       ` Pierre-Louis Bossart
2014-10-22 19:45                         ` Devin Heitmueller
2014-10-24 14:44                           ` Shuah Khan
2014-10-25 12:44                         ` Mauro Carvalho Chehab
2014-10-25 12:44                           ` [alsa-devel] " Mauro Carvalho Chehab
2014-10-25 13:20                         ` Mauro Carvalho Chehab
2014-10-25 13:41                         ` Mauro Carvalho Chehab
2014-10-25 13:41                           ` [alsa-devel] " Mauro Carvalho Chehab
2014-10-26  8:27                           ` Takashi Iwai
2014-10-27 12:52                             ` Mauro Carvalho Chehab
2014-10-28 21:15                               ` Shuah Khan
2014-10-28 23:42                                 ` [RFCv1] Media Token API needs - Was: " Mauro Carvalho Chehab
2014-10-29  0:00                                   ` Mauro Carvalho Chehab
2014-10-29 11:19                                     ` Mauro Carvalho Chehab
2014-10-29 16:06                                   ` Shuah Khan
2014-10-29 17:56                                     ` Mauro Carvalho Chehab
2014-11-04 23:08                                       ` [RFCv2] Media Token API Spec Shuah Khan
2014-11-10 14:15                                         ` Hans Verkuil
2014-11-10 14:15                                           ` Hans Verkuil
2014-11-18 21:15                                         ` Sakari Ailus
2014-11-18 21:27                                           ` Shuah Khan
2014-10-21 17:32                     ` Shuah Khan [this message]
2014-10-22 15:24                       ` [alsa-devel] [PATCH v2 5/6] sound/usb: pcm changes to use media token api Hans Verkuil
2014-10-25 10:57                       ` Mauro Carvalho Chehab
2014-10-27 15:47                         ` [alsa-devel] " Shuah Khan
2014-10-14 14:58 ` [PATCH v2 6/6] media: au0828-core changes to create and destroy media Shuah Khan
2014-10-15 16:48 ` [PATCH v2 0/6] media token resource framework Takashi Iwai
2014-10-15 20:21   ` Shuah Khan
2014-10-16 14:02     ` Takashi Iwai
2014-10-29  9:17 ` Sakari Ailus
2014-10-29  9:33   ` Mauro Carvalho Chehab
2014-10-29  9:33     ` Mauro Carvalho Chehab

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=5446989A.3010000@osg.samsung.com \
    --to=shuahkh@osg.samsung.com \
    --cc=akpm@linux-foundation.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=crope@iki.fi \
    --cc=dheitmueller@kernellabs.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hverkuil@xs4all.nl \
    --cc=lars@metafoo.de \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux@eikelenboom.it \
    --cc=m.chehab@samsung.com \
    --cc=olebowle@gmx.com \
    --cc=perex@perex.cz \
    --cc=prabhakar.csengg@gmail.com \
    --cc=ramakrmu@cisco.com \
    --cc=sakari.ailus@linux.intel.com \
    --cc=tim.gardner@canonical.com \
    --cc=tiwai@suse.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.