{"action":"created","comment":{"url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/pulls/comments/80049531","id":80049531,"diff_hunk":"@@ -564,9 +635,23 @@ inline void cVideoInput::Receive(const uchar *data, int length)\n   m_VideoBuffer->Put(data, length);\n }\n \n-void cVideoInput::Retune()\n+void cVideoInput::RequestRetune()\n+{\n+  m_RetuneRequested = true;\n+  m_Event.Signal();\n+}\n+\n+cVideoInput::eReceivingStatus cVideoInput::ReceivingStatus()\n {\n-  cMutexLock lock(&m_Mutex);\n-  m_IsRetune = true;\n-  m_Event.Broadcast();\n+  if (!m_Device || !m_Receiver || !m_DummyReceiver)\n+    return RETUNE;\n+  if (m_RetuneRequested || !m_Receiver->IsAttached())\n+  {\n+    (void)m_Device->Receiving();  // wait for the receivers mutex\n+    if (!m_DummyReceiver->IsAttached())  // DetachAllReceivers() was called\n+      return CLOSE;\n+    else if (!m_PmtChange)","path":"videoinput.c","position":183,"original_position":183,"commit_id":"b6bf9805f54459838cebe4b5ebd99d792fd1b699","original_commit_id":"b6bf9805f54459838cebe4b5ebd99d792fd1b699","user":{"login":"glenvt18","id":8867360,"avatar_url":"https://avatars.githubusercontent.com/u/8867360?v=3","gravatar_id":"","url":"https://api.github.com/users/glenvt18","html_url":"https://github.com/glenvt18","followers_url":"https://api.github.com/users/glenvt18/followers","following_url":"https://api.github.com/users/glenvt18/following{/other_user}","gists_url":"https://api.github.com/users/glenvt18/gists{/gist_id}","starred_url":"https://api.github.com/users/glenvt18/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glenvt18/subscriptions","organizations_url":"https://api.github.com/users/glenvt18/orgs","repos_url":"https://api.github.com/users/glenvt18/repos","events_url":"https://api.github.com/users/glenvt18/events{/privacy}","received_events_url":"https://api.github.com/users/glenvt18/received_events","type":"User","site_admin":false},"body":"Receivers operations (`AttachReceiver()`, `DetachXXX()`, `Receiving()`) are protected by a mutex, but `IsAttached()` is not. It just reads `device` value. At the moment we get `m_Receiver->device == NULL` (`!IsAttached()`), `m_DummyReceiver->device` might be not NULL - `DetachAllReceivers()` hasn't yet detached it. That's why we have to wait for `DetachAllReceivers()` to complete. At this point we can be sure that if both receivers has been detached, we get two NULL `device`s. In other words, without `Receiving()` (or any other call that holds the receiver mutex) it's possible to get a false RETUNE when it should have been CLOSE. This would clash with recording.\r\nBut `device` members are not atomic/protected as well as `m_RetuneRequested`. We can use our own 'protected' flags set by receiver callbacks instead. I'll rework this and set a fix as a new PR. Do you agree?\r\nDo we still need m_PmtChange?","created_at":"2016-09-22T14:14:15Z","updated_at":"2016-09-22T14:14:16Z","html_url":"https://github.com/FernetMenta/vdr-plugin-vnsiserver/pull/73#discussion_r80049531","pull_request_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/pulls/73","_links":{"self":{"href":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/pulls/comments/80049531"},"html":{"href":"https://github.com/FernetMenta/vdr-plugin-vnsiserver/pull/73#discussion_r80049531"},"pull_request":{"href":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/pulls/73"}}},"pull_request":{"url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/pulls/73","id":86182839,"html_url":"https://github.com/FernetMenta/vdr-plugin-vnsiserver/pull/73","diff_url":"https://github.com/FernetMenta/vdr-plugin-vnsiserver/pull/73.diff","patch_url":"https://github.com/FernetMenta/vdr-plugin-vnsiserver/pull/73.patch","issue_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/issues/73","number":73,"state":"closed","locked":false,"title":"Retune fixes","user":{"login":"glenvt18","id":8867360,"avatar_url":"https://avatars.githubusercontent.com/u/8867360?v=3","gravatar_id":"","url":"https://api.github.com/users/glenvt18","html_url":"https://github.com/glenvt18","followers_url":"https://api.github.com/users/glenvt18/followers","following_url":"https://api.github.com/users/glenvt18/following{/other_user}","gists_url":"https://api.github.com/users/glenvt18/gists{/gist_id}","starred_url":"https://api.github.com/users/glenvt18/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glenvt18/subscriptions","organizations_url":"https://api.github.com/users/glenvt18/orgs","repos_url":"https://api.github.com/users/glenvt18/repos","events_url":"https://api.github.com/users/glenvt18/events{/privacy}","received_events_url":"https://api.github.com/users/glenvt18/received_events","type":"User","site_admin":false},"body":"This PR fixes two issues with re-tune:\r\n\r\n1.  When a higher priority recording or streaming task is about to zap to another transponder on the device from which VNSI is currently streaming, it detaches all receivers from the device, which, in turn, triggers re-tune. Since VDR has no synchronization mechanism for zapping (`GetDevice()->SwitchChannel()->AttachReceiver()` chain), a race occurs. The result is usually that the recording calls an emergency exit after not receiving TS packets for 30 seconds. To reproduce this, start streaming a channel, then start recording (or another VNSI streaming with a higher priority) of a channel from another transponder. VDR should restart in 30 seconds. The proposed solution is to disable re-tune in such cases. Even if (when) VDR had zapping synchronization, re-tuning after the device has been switched to another transponder by a higher priority task wouldn't be practical anyway.\r\nTo detect whether to re-tune or not, a helper dummy receiver is attached to the device. If this dummy receiver is detached, re-tuning should be disabled.\r\n\r\n2.  `DisableScrambleTimeout` option only works for clients with priority < 0 (after 9a8fef72 it's not possible anymore). For CAMs like dvbapi, re-tuning after scrambling timeout has expired doesn't help because the channel is then being marked 'checked' (blacklisted) for 15 seconds. To reproduce this, add a delay > 3 seconds to the CAM, or switch it off, and, after some time, switch it on. Solution: 'uncheck' before zapping (`GetDevice()` call).","created_at":"2016-09-21T15:12:40Z","updated_at":"2016-09-22T14:14:16Z","closed_at":"2016-09-22T07:24:49Z","merged_at":"2016-09-22T07:24:49Z","merge_commit_sha":"d011975e1a9a1543a39570a5c972ed3e8c37bf6c","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/pulls/73/commits","review_comments_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/pulls/73/comments","review_comment_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/pulls/comments{/number}","comments_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/issues/73/comments","statuses_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/statuses/b6bf9805f54459838cebe4b5ebd99d792fd1b699","head":{"label":"glenvt18:retune-fixes","ref":"retune-fixes","sha":"b6bf9805f54459838cebe4b5ebd99d792fd1b699","user":{"login":"glenvt18","id":8867360,"avatar_url":"https://avatars.githubusercontent.com/u/8867360?v=3","gravatar_id":"","url":"https://api.github.com/users/glenvt18","html_url":"https://github.com/glenvt18","followers_url":"https://api.github.com/users/glenvt18/followers","following_url":"https://api.github.com/users/glenvt18/following{/other_user}","gists_url":"https://api.github.com/users/glenvt18/gists{/gist_id}","starred_url":"https://api.github.com/users/glenvt18/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glenvt18/subscriptions","organizations_url":"https://api.github.com/users/glenvt18/orgs","repos_url":"https://api.github.com/users/glenvt18/repos","events_url":"https://api.github.com/users/glenvt18/events{/privacy}","received_events_url":"https://api.github.com/users/glenvt18/received_events","type":"User","site_admin":false},"repo":{"id":52533766,"name":"vdr-plugin-vnsiserver","full_name":"glenvt18/vdr-plugin-vnsiserver","owner":{"login":"glenvt18","id":8867360,"avatar_url":"https://avatars.githubusercontent.com/u/8867360?v=3","gravatar_id":"","url":"https://api.github.com/users/glenvt18","html_url":"https://github.com/glenvt18","followers_url":"https://api.github.com/users/glenvt18/followers","following_url":"https://api.github.com/users/glenvt18/following{/other_user}","gists_url":"https://api.github.com/users/glenvt18/gists{/gist_id}","starred_url":"https://api.github.com/users/glenvt18/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glenvt18/subscriptions","organizations_url":"https://api.github.com/users/glenvt18/orgs","repos_url":"https://api.github.com/users/glenvt18/repos","events_url":"https://api.github.com/users/glenvt18/events{/privacy}","received_events_url":"https://api.github.com/users/glenvt18/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/glenvt18/vdr-plugin-vnsiserver","description":"VDR plugin to handle XBMC clients.","fork":true,"url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver","forks_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/forks","keys_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/keys{/key_id}","collaborators_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/teams","hooks_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/hooks","issue_events_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/issues/events{/number}","events_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/events","assignees_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/assignees{/user}","branches_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/branches{/branch}","tags_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/tags","blobs_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/git/refs{/sha}","trees_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/git/trees{/sha}","statuses_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/statuses/{sha}","languages_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/languages","stargazers_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/stargazers","contributors_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/contributors","subscribers_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/subscribers","subscription_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/subscription","commits_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/commits{/sha}","git_commits_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/git/commits{/sha}","comments_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/comments{/number}","issue_comment_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/issues/comments{/number}","contents_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/contents/{+path}","compare_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/compare/{base}...{head}","merges_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/merges","archive_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/downloads","issues_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/issues{/number}","pulls_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/pulls{/number}","milestones_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/milestones{/number}","notifications_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/labels{/name}","releases_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/releases{/id}","deployments_url":"https://api.github.com/repos/glenvt18/vdr-plugin-vnsiserver/deployments","created_at":"2016-02-25T15:05:06Z","updated_at":"2016-02-25T15:05:07Z","pushed_at":"2016-09-22T12:55:18Z","git_url":"git://github.com/glenvt18/vdr-plugin-vnsiserver.git","ssh_url":"git@github.com:glenvt18/vdr-plugin-vnsiserver.git","clone_url":"https://github.com/glenvt18/vdr-plugin-vnsiserver.git","svn_url":"https://github.com/glenvt18/vdr-plugin-vnsiserver","homepage":"","size":572,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"FernetMenta:master","ref":"master","sha":"abd24d540184cccfa71e913342728d2434270ccc","user":{"login":"FernetMenta","id":576009,"avatar_url":"https://avatars.githubusercontent.com/u/576009?v=3","gravatar_id":"","url":"https://api.github.com/users/FernetMenta","html_url":"https://github.com/FernetMenta","followers_url":"https://api.github.com/users/FernetMenta/followers","following_url":"https://api.github.com/users/FernetMenta/following{/other_user}","gists_url":"https://api.github.com/users/FernetMenta/gists{/gist_id}","starred_url":"https://api.github.com/users/FernetMenta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FernetMenta/subscriptions","organizations_url":"https://api.github.com/users/FernetMenta/orgs","repos_url":"https://api.github.com/users/FernetMenta/repos","events_url":"https://api.github.com/users/FernetMenta/events{/privacy}","received_events_url":"https://api.github.com/users/FernetMenta/received_events","type":"User","site_admin":false},"repo":{"id":17914038,"name":"vdr-plugin-vnsiserver","full_name":"FernetMenta/vdr-plugin-vnsiserver","owner":{"login":"FernetMenta","id":576009,"avatar_url":"https://avatars.githubusercontent.com/u/576009?v=3","gravatar_id":"","url":"https://api.github.com/users/FernetMenta","html_url":"https://github.com/FernetMenta","followers_url":"https://api.github.com/users/FernetMenta/followers","following_url":"https://api.github.com/users/FernetMenta/following{/other_user}","gists_url":"https://api.github.com/users/FernetMenta/gists{/gist_id}","starred_url":"https://api.github.com/users/FernetMenta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FernetMenta/subscriptions","organizations_url":"https://api.github.com/users/FernetMenta/orgs","repos_url":"https://api.github.com/users/FernetMenta/repos","events_url":"https://api.github.com/users/FernetMenta/events{/privacy}","received_events_url":"https://api.github.com/users/FernetMenta/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/FernetMenta/vdr-plugin-vnsiserver","description":"VDR plugin to handle XBMC clients.","fork":false,"url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver","forks_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/forks","keys_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/keys{/key_id}","collaborators_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/teams","hooks_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/hooks","issue_events_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/issues/events{/number}","events_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/events","assignees_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/assignees{/user}","branches_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/branches{/branch}","tags_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/tags","blobs_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/git/refs{/sha}","trees_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/git/trees{/sha}","statuses_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/statuses/{sha}","languages_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/languages","stargazers_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/stargazers","contributors_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/contributors","subscribers_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/subscribers","subscription_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/subscription","commits_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/commits{/sha}","git_commits_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/git/commits{/sha}","comments_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/comments{/number}","issue_comment_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/issues/comments{/number}","contents_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/contents/{+path}","compare_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/compare/{base}...{head}","merges_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/merges","archive_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/downloads","issues_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/issues{/number}","pulls_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/pulls{/number}","milestones_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/milestones{/number}","notifications_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/labels{/name}","releases_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/releases{/id}","deployments_url":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/deployments","created_at":"2014-03-19T17:39:56Z","updated_at":"2016-08-20T01:04:28Z","pushed_at":"2016-09-22T07:24:50Z","git_url":"git://github.com/FernetMenta/vdr-plugin-vnsiserver.git","ssh_url":"git@github.com:FernetMenta/vdr-plugin-vnsiserver.git","clone_url":"https://github.com/FernetMenta/vdr-plugin-vnsiserver.git","svn_url":"https://github.com/FernetMenta/vdr-plugin-vnsiserver","homepage":"","size":756,"stargazers_count":15,"watchers_count":15,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":22,"mirror_url":null,"open_issues_count":8,"forks":22,"open_issues":8,"watchers":15,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/pulls/73"},"html":{"href":"https://github.com/FernetMenta/vdr-plugin-vnsiserver/pull/73"},"issue":{"href":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/issues/73"},"comments":{"href":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/issues/73/comments"},"review_comments":{"href":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/pulls/73/comments"},"review_comment":{"href":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/pulls/73/commits"},"statuses":{"href":"https://api.github.com/repos/FernetMenta/vdr-plugin-vnsiserver/statuses/b6bf9805f54459838cebe4b5ebd99d792fd1b699"}}}}
{"actor":{"display_login":"glenvt18"}}