linux-kernel-mentees.lists.linuxfoundation.org archive mirror
 help / color / mirror / Atom feed
From: hverkuil at xs4all.nl (Hans Verkuil)
Subject: [Linux-kernel-mentees] [PATCH v2 1/2] cec-follower: add tuner step increment/decrement
Date: Wed, 25 Sep 2019 08:54:29 +0200	[thread overview]
Message-ID: <fb849c63-6bac-5d40-f78d-f0ac57250a95@xs4all.nl> (raw)
In-Reply-To: <20190924192445.93575-2-c0d1n61at3@gmail.com>

Hi Jiunn,

On 9/24/19 9:24 PM, Jiunn Chang wrote:
> Tuner step increment/decrement will select the next highest or next
> lowest service frequency.  There are a total of three possible
> frequencies from analog_freqs_khz given a broadcast type and system.
> 
> Opcodes implemented:
>   - <Tuner Step Increment>
>   - <Tuner Step Decrement>
> 
> Signed-off-by: Jiunn Chang <c0d1n61at3 at gmail.com>
> ---
>  utils/cec-follower/cec-tuner.cpp | 47 ++++++++++++++++++++++++++++++--
>  1 file changed, 44 insertions(+), 3 deletions(-)
> 
> diff --git a/utils/cec-follower/cec-tuner.cpp b/utils/cec-follower/cec-tuner.cpp
> index acc3fd00..1a9b9d90 100644
> --- a/utils/cec-follower/cec-tuner.cpp
> +++ b/utils/cec-follower/cec-tuner.cpp
> @@ -135,6 +135,22 @@ static bool analog_set_tuner_dev_info(struct node *node, struct cec_msg *msg)
>  	return false;
>  }
>  
> +static int analog_find_freq_index(struct cec_op_tuner_device_info *info)
> +{
> +	if (info->analog.ana_freq == 0)
> +		return -1;
> +
> +	int ana_freq_khz = (info->analog.ana_freq * 625) / 10;
> +
> +	for (int i = 0; i < NUM_ANALOG_FREQS; i++) {
> +		int freq = analog_freqs_khz[info->analog.ana_bcast_type][info->analog.bcast_system][i];
> +
> +		if (ana_freq_khz == freq)
> +			return i;
> +	}
> +	return -1;
> +}

Hmm, I don't like this code. I think that it would be cleaner to just add:

static unsigned int analog_freq_idx[3][9];

Which contains the index of the current frequency for each bcast_type/system
combination.

This ensures that 1) there always is a current frequency and 2) tuner stepping
is now trivial since all you need to do is to update the corresponding index.

Now, that said, I was thinking that it would be nice to have one bcast_type/system
combo with no channels at all, since that's a nice test as well.

I think that setting secam-lq for satellite to { 0, 0, 0 } to indicate no
defined channels would make a nice test case.

Something for a follow-up patch, though.

> +
>  void process_tuner_record_timer_msgs(struct node *node, struct cec_msg &msg, unsigned me)
>  {
>  	bool is_bcast = cec_msg_is_broadcast(&msg);
> @@ -178,12 +194,37 @@ void process_tuner_record_timer_msgs(struct node *node, struct cec_msg &msg, uns
>  		return;
>  
>  	case CEC_MSG_SELECT_DIGITAL_SERVICE:
> -	case CEC_MSG_TUNER_STEP_DECREMENT:
> -	case CEC_MSG_TUNER_STEP_INCREMENT:
> -		if (!cec_has_tuner(1 << me))
> +	case CEC_MSG_TUNER_STEP_DECREMENT: {
> +		if (!cec_has_tuner(1 << me) && !cec_has_tv(1 << me))
>  			break;
> +
> +		struct cec_op_tuner_device_info *info = &node->state.tuner_dev_info;
> +		int freq_idx = analog_find_freq_index(info);
> +		int idx = (freq_idx == 0) ? NUM_ANALOG_FREQS : freq_idx;
> +
> +		if (info->is_analog) {
> +			int freq = analog_freqs_khz[info->analog.ana_bcast_type][info->analog.bcast_system][--idx];
> +
> +			info->analog.ana_freq = (freq * 10) / 625;
> +		}
>  		return;
> +	}
> +
> +	case CEC_MSG_TUNER_STEP_INCREMENT: {
> +		if (!cec_has_tuner(1 << me) && !cec_has_tv(1 << me))
> +			break;
>  
> +		struct cec_op_tuner_device_info *info = &node->state.tuner_dev_info;
> +		int freq_idx = analog_find_freq_index(info);
> +		int idx = (freq_idx == NUM_ANALOG_FREQS - 1) ? -1 : freq_idx;
> +
> +		if (info->is_analog) {
> +			int freq = analog_freqs_khz[info->analog.ana_bcast_type][info->analog.bcast_system][++idx];
> +
> +			info->analog.ana_freq = (freq * 10) / 625;
> +		}
> +		return;
> +	}
>  
>  		/*
>  		  One Touch Record
> 

Regards,

	Hans

WARNING: multiple messages have this Message-ID (diff)
From: hverkuil@xs4all.nl (Hans Verkuil)
Subject: [Linux-kernel-mentees] [PATCH v2 1/2] cec-follower: add tuner step increment/decrement
Date: Wed, 25 Sep 2019 08:54:29 +0200	[thread overview]
Message-ID: <fb849c63-6bac-5d40-f78d-f0ac57250a95@xs4all.nl> (raw)
Message-ID: <20190925065429.ljiy5JNVYPy-h7uT6TIVD1BMrM1AkQIkp04tecUlSfc@z> (raw)
In-Reply-To: <20190924192445.93575-2-c0d1n61at3@gmail.com>

Hi Jiunn,

On 9/24/19 9:24 PM, Jiunn Chang wrote:
> Tuner step increment/decrement will select the next highest or next
> lowest service frequency.  There are a total of three possible
> frequencies from analog_freqs_khz given a broadcast type and system.
> 
> Opcodes implemented:
>   - <Tuner Step Increment>
>   - <Tuner Step Decrement>
> 
> Signed-off-by: Jiunn Chang <c0d1n61at3 at gmail.com>
> ---
>  utils/cec-follower/cec-tuner.cpp | 47 ++++++++++++++++++++++++++++++--
>  1 file changed, 44 insertions(+), 3 deletions(-)
> 
> diff --git a/utils/cec-follower/cec-tuner.cpp b/utils/cec-follower/cec-tuner.cpp
> index acc3fd00..1a9b9d90 100644
> --- a/utils/cec-follower/cec-tuner.cpp
> +++ b/utils/cec-follower/cec-tuner.cpp
> @@ -135,6 +135,22 @@ static bool analog_set_tuner_dev_info(struct node *node, struct cec_msg *msg)
>  	return false;
>  }
>  
> +static int analog_find_freq_index(struct cec_op_tuner_device_info *info)
> +{
> +	if (info->analog.ana_freq == 0)
> +		return -1;
> +
> +	int ana_freq_khz = (info->analog.ana_freq * 625) / 10;
> +
> +	for (int i = 0; i < NUM_ANALOG_FREQS; i++) {
> +		int freq = analog_freqs_khz[info->analog.ana_bcast_type][info->analog.bcast_system][i];
> +
> +		if (ana_freq_khz == freq)
> +			return i;
> +	}
> +	return -1;
> +}

Hmm, I don't like this code. I think that it would be cleaner to just add:

static unsigned int analog_freq_idx[3][9];

Which contains the index of the current frequency for each bcast_type/system
combination.

This ensures that 1) there always is a current frequency and 2) tuner stepping
is now trivial since all you need to do is to update the corresponding index.

Now, that said, I was thinking that it would be nice to have one bcast_type/system
combo with no channels at all, since that's a nice test as well.

I think that setting secam-lq for satellite to { 0, 0, 0 } to indicate no
defined channels would make a nice test case.

Something for a follow-up patch, though.

> +
>  void process_tuner_record_timer_msgs(struct node *node, struct cec_msg &msg, unsigned me)
>  {
>  	bool is_bcast = cec_msg_is_broadcast(&msg);
> @@ -178,12 +194,37 @@ void process_tuner_record_timer_msgs(struct node *node, struct cec_msg &msg, uns
>  		return;
>  
>  	case CEC_MSG_SELECT_DIGITAL_SERVICE:
> -	case CEC_MSG_TUNER_STEP_DECREMENT:
> -	case CEC_MSG_TUNER_STEP_INCREMENT:
> -		if (!cec_has_tuner(1 << me))
> +	case CEC_MSG_TUNER_STEP_DECREMENT: {
> +		if (!cec_has_tuner(1 << me) && !cec_has_tv(1 << me))
>  			break;
> +
> +		struct cec_op_tuner_device_info *info = &node->state.tuner_dev_info;
> +		int freq_idx = analog_find_freq_index(info);
> +		int idx = (freq_idx == 0) ? NUM_ANALOG_FREQS : freq_idx;
> +
> +		if (info->is_analog) {
> +			int freq = analog_freqs_khz[info->analog.ana_bcast_type][info->analog.bcast_system][--idx];
> +
> +			info->analog.ana_freq = (freq * 10) / 625;
> +		}
>  		return;
> +	}
> +
> +	case CEC_MSG_TUNER_STEP_INCREMENT: {
> +		if (!cec_has_tuner(1 << me) && !cec_has_tv(1 << me))
> +			break;
>  
> +		struct cec_op_tuner_device_info *info = &node->state.tuner_dev_info;
> +		int freq_idx = analog_find_freq_index(info);
> +		int idx = (freq_idx == NUM_ANALOG_FREQS - 1) ? -1 : freq_idx;
> +
> +		if (info->is_analog) {
> +			int freq = analog_freqs_khz[info->analog.ana_bcast_type][info->analog.bcast_system][++idx];
> +
> +			info->analog.ana_freq = (freq * 10) / 625;
> +		}
> +		return;
> +	}
>  
>  		/*
>  		  One Touch Record
> 

Regards,

	Hans

  parent reply	other threads:[~2019-09-25  6:54 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-24 14:17 [Linux-kernel-mentees] [PATCH 0/2] cec-compliance: tuner control c0d1n61at3
2019-09-24 14:17 ` Jiunn Chang
2019-09-24 14:17 ` [Linux-kernel-mentees] [PATCH 1/2] cec-follower: add tuner step increment/decrement c0d1n61at3
2019-09-24 14:17   ` Jiunn Chang
2019-09-24 15:20   ` hverkuil
2019-09-24 15:20     ` Hans Verkuil
2019-09-24 14:17 ` [Linux-kernel-mentees] [PATCH 2/2] cec-compliance: add/refactor tuner control tests c0d1n61at3
2019-09-24 14:17   ` Jiunn Chang
2019-09-24 19:24 ` [Linux-kernel-mentees] [PATCH v2 0/2] cec-compliance: tuner control c0d1n61at3
2019-09-24 19:24   ` Jiunn Chang
2019-09-30  4:30   ` [Linux-kernel-mentees] [PATCH v3 0/3] " c0d1n61at3
2019-09-30  4:30     ` Jiunn Chang
2019-10-01  3:18     ` [Linux-kernel-mentees] [PATCH v4 " c0d1n61at3
2019-10-01  3:18       ` Jiunn Chang
2019-10-03  3:18       ` [Linux-kernel-mentees] [PATCH v5 0/2] " c0d1n61at3
2019-10-03  3:18         ` Jiunn Chang
2019-10-04  4:05         ` [Linux-kernel-mentees] [PATCH v6 0/1] " c0d1n61at3
2019-10-04  4:05           ` Jiunn Chang
2019-10-04  4:05         ` [Linux-kernel-mentees] [PATCH v6 1/1] Add test for new features in cec-follower c0d1n61at3
2019-10-04  4:05           ` Jiunn Chang
2019-10-03  3:18       ` [Linux-kernel-mentees] [PATCH v5 1/2] cec-follower: add tuner step increment/decrement c0d1n61at3
2019-10-03  3:18         ` Jiunn Chang
2019-10-03  3:18       ` [Linux-kernel-mentees] [PATCH v5 2/2] Add test for new features in cec-follower c0d1n61at3
2019-10-03  3:18         ` Jiunn Chang
2019-10-03  6:51         ` hverkuil
2019-10-03  6:51           ` Hans Verkuil
2019-10-01  3:18     ` [Linux-kernel-mentees] [PATCH v4 1/3] cec-follower: fix bugs for tuner emulation c0d1n61at3
2019-10-01  3:18       ` Jiunn Chang
2019-10-01  3:18     ` [Linux-kernel-mentees] [PATCH v4 2/3] cec-follower: add tuner step increment/decrement c0d1n61at3
2019-10-01  3:18       ` Jiunn Chang
2019-10-01  7:12       ` hverkuil
2019-10-01  7:12         ` Hans Verkuil
2019-10-01  3:18     ` [Linux-kernel-mentees] [PATCH v4 3/3] cec-compliance: add tuner control test c0d1n61at3
2019-10-01  3:18       ` Jiunn Chang
2019-10-01  7:51       ` hverkuil
2019-10-01  7:51         ` Hans Verkuil
2019-09-30  4:30   ` [Linux-kernel-mentees] [PATCH v3 1/3] cec-follower: fix bugs for tuner emulation c0d1n61at3
2019-09-30  4:30     ` Jiunn Chang
2019-09-30  9:12     ` hverkuil
2019-09-30  9:12       ` Hans Verkuil
2019-09-30  4:30   ` [Linux-kernel-mentees] [PATCH v3 2/3] cec-follower: add tuner step increment/decrement c0d1n61at3
2019-09-30  4:30     ` Jiunn Chang
2019-09-30  9:35     ` hverkuil
2019-09-30  9:35       ` Hans Verkuil
2019-09-30  4:30   ` [Linux-kernel-mentees] [PATCH v3 3/3] cec-compliance: refactor tuner control tests c0d1n61at3
2019-09-30  4:30     ` Jiunn Chang
2019-09-30  9:43     ` hverkuil
2019-09-30  9:43       ` Hans Verkuil
2019-09-24 19:24 ` [Linux-kernel-mentees] [PATCH v2 1/2] cec-follower: add tuner step increment/decrement c0d1n61at3
2019-09-24 19:24   ` Jiunn Chang
2019-09-24 19:31   ` skhan
2019-09-24 19:31     ` Shuah Khan
2019-09-25  6:54   ` hverkuil [this message]
2019-09-25  6:54     ` Hans Verkuil
2019-09-25  7:12     ` hverkuil
2019-09-25  7:12       ` Hans Verkuil
2019-09-24 19:24 ` [Linux-kernel-mentees] [PATCH v2 2/2] cec-compliance: add/refactor tuner control tests c0d1n61at3
2019-09-24 19:24   ` Jiunn Chang
2019-09-24 19:44   ` skhan
2019-09-24 19:44     ` Shuah Khan
2019-09-25  7:22   ` hverkuil
2019-09-25  7:22     ` 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=fb849c63-6bac-5d40-f78d-f0ac57250a95@xs4all.nl \
    --to=linux-kernel-mentees@lists.linux-foundation.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;
as well as URLs for NNTP newsgroup(s).