{"action":"created","comment":{"url":"https://api.github.com/repos/cocos2d/cocos2d-x/pulls/comments/67892322","id":67892322,"diff_hunk":"@@ -0,0 +1,666 @@\n+/****************************************************************************\n+Copyright (c) 2016 Chukong Technologies Inc.\n+\n+http://www.cocos2d-x.org\n+\n+Permission is hereby granted, free of charge, to any person obtaining a copy\n+of this software and associated documentation files (the \"Software\"), to deal\n+in the Software without restriction, including without limitation the rights\n+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+copies of the Software, and to permit persons to whom the Software is\n+furnished to do so, subject to the following conditions:\n+\n+The above copyright notice and this permission notice shall be included in\n+all copies or substantial portions of the Software.\n+\n+THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n+THE SOFTWARE.\n+****************************************************************************/\n+\n+#include \"AudioDecoder.h\"\n+#include \"AudioResampler.h\"\n+#include \"PcmBufferProvider.h\"\n+\n+#include <android/log.h>\n+#include <unistd.h>\n+\n+using namespace cocos2d;\n+\n+#define LOG_TAG \"AudioDecoder\"\n+#define LOGD(...)  __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG,__VA_ARGS__)\n+#define LOGE(...)  __android_log_print(ANDROID_LOG_ERROR, LOG_TAG,__VA_ARGS__)\n+\n+/* size of the struct to retrieve the PCM format metadata values: the values we're interested in\n+ * are SLuint32, but it is saved in the data field of a SLMetadataInfo, hence the larger size.\n+ * Nate that this size is queried and displayed at l.452 for demonstration/test purposes.\n+ *  */\n+#define PCM_METADATA_VALUE_SIZE 32\n+\n+/* used to detect errors likely to have occured when the OpenSL ES framework fails to open\n+ * a resource, for instance because a file URI is invalid, or an HTTP server doesn't respond.\n+ */\n+#define PREFETCHEVENT_ERROR_CANDIDATE (SL_PREFETCHEVENT_STATUSCHANGE | SL_PREFETCHEVENT_FILLLEVELCHANGE)\n+\n+//-----------------------------------------------------------------\n+\n+static void checkMetaData(int index, const char* key)\n+{\n+    if (index != -1) {\n+        LOGD(\"Key %s is at index %d\", key, index);\n+    } else {\n+        LOGE(\"Unable to find key %s\", key);\n+    }\n+}\n+\n+class SLAudioDecoderCallbackProxy\n+{\n+public:\n+    //-----------------------------------------------------------------\n+    /* Callback for \"prefetch\" events, here used to detect audio resource opening errors */\n+    static void prefetchEventCallback( SLPrefetchStatusItf caller,  void* context, SLuint32 event)\n+    {\n+        AudioDecoder* thiz = reinterpret_cast<AudioDecoder*>(context);\n+        thiz->prefetchCallback(caller, event);\n+    }\n+\n+    static void decPlayCallback(SLAndroidSimpleBufferQueueItf queueItf, void* context)\n+    {\n+        AudioDecoder* thiz = reinterpret_cast<AudioDecoder*>(context);\n+        thiz->decodeToPcmCallback(queueItf);\n+    }\n+\n+    static void decProgressCallback(SLPlayItf caller, void* context, SLuint32 event)\n+    {\n+        AudioDecoder* thiz = reinterpret_cast<AudioDecoder*>(context);\n+        thiz->decodeProgressCallback(caller, event);\n+    }\n+};\n+\n+AudioDecoder::AudioDecoder(SLEngineItf engineItf, const std::string &url, int sampleRate)\n+        : _engineItf(engineItf)\n+        , _url(url)\n+        , _playObj(nullptr)\n+        , _pcmMetaData(nullptr)\n+        , _formatQueried(false)\n+        , _prefetchError(false)\n+        , _counter(0)\n+        , _numChannelsKeyIndex(-1)\n+        , _sampleRateKeyIndex(-1)\n+        , _bitsPerSampleKeyIndex(-1)\n+        , _containerSizeKeyIndex(-1)\n+        , _channelMaskKeyIndex(-1)\n+        , _endiannessKeyIndex(-1)\n+        , _eos(false)\n+        , _sampleRate(sampleRate)\n+        , _assetFd(0)\n+{\n+    memset(_pcmData, 0, sizeof(_pcmData));\n+    auto pcmBuffer = std::make_shared<std::vector<char>>();\n+    pcmBuffer->reserve(4096);\n+    _result.pcmBuffer = pcmBuffer;\n+}\n+\n+AudioDecoder::~AudioDecoder()\n+{\n+    if (_pcmMetaData != nullptr)\n+    {\n+        free(_pcmMetaData);\n+        _pcmMetaData = nullptr;","path":"cocos/audio/android/AudioDecoder.cpp","position":113,"original_position":113,"commit_id":"fd63f420838391f0f7bf02ce8ed765e06e3564bb","original_commit_id":"fd63f420838391f0f7bf02ce8ed765e06e3564bb","user":{"login":"j-jorge","id":2023446,"avatar_url":"https://avatars.githubusercontent.com/u/2023446?v=3","gravatar_id":"","url":"https://api.github.com/users/j-jorge","html_url":"https://github.com/j-jorge","followers_url":"https://api.github.com/users/j-jorge/followers","following_url":"https://api.github.com/users/j-jorge/following{/other_user}","gists_url":"https://api.github.com/users/j-jorge/gists{/gist_id}","starred_url":"https://api.github.com/users/j-jorge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/j-jorge/subscriptions","organizations_url":"https://api.github.com/users/j-jorge/orgs","repos_url":"https://api.github.com/users/j-jorge/repos","events_url":"https://api.github.com/users/j-jorge/events{/privacy}","received_events_url":"https://api.github.com/users/j-jorge/received_events","type":"User","site_admin":false},"body":"`_pcmMetaData` won't be read after the destructor, you can skip this assignment.","created_at":"2016-06-21T15:33:17Z","updated_at":"2016-06-21T15:33:17Z","html_url":"https://github.com/cocos2d/cocos2d-x/pull/15875#discussion_r67892322","pull_request_url":"https://api.github.com/repos/cocos2d/cocos2d-x/pulls/15875","_links":{"self":{"href":"https://api.github.com/repos/cocos2d/cocos2d-x/pulls/comments/67892322"},"html":{"href":"https://github.com/cocos2d/cocos2d-x/pull/15875#discussion_r67892322"},"pull_request":{"href":"https://api.github.com/repos/cocos2d/cocos2d-x/pulls/15875"}}},"pull_request":{"url":"https://api.github.com/repos/cocos2d/cocos2d-x/pulls/15875","id":74216477,"html_url":"https://github.com/cocos2d/cocos2d-x/pull/15875","diff_url":"https://github.com/cocos2d/cocos2d-x/pull/15875.diff","patch_url":"https://github.com/cocos2d/cocos2d-x/pull/15875.patch","issue_url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/15875","number":15875,"state":"open","locked":false,"title":"[big refactoring] Audio latency fix for Android. Support to preload effects on Android now.","user":{"login":"dumganhar","id":493372,"avatar_url":"https://avatars.githubusercontent.com/u/493372?v=3","gravatar_id":"","url":"https://api.github.com/users/dumganhar","html_url":"https://github.com/dumganhar","followers_url":"https://api.github.com/users/dumganhar/followers","following_url":"https://api.github.com/users/dumganhar/following{/other_user}","gists_url":"https://api.github.com/users/dumganhar/gists{/gist_id}","starred_url":"https://api.github.com/users/dumganhar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dumganhar/subscriptions","organizations_url":"https://api.github.com/users/dumganhar/orgs","repos_url":"https://api.github.com/users/dumganhar/repos","events_url":"https://api.github.com/users/dumganhar/events{/privacy}","received_events_url":"https://api.github.com/users/dumganhar/received_events","type":"User","site_admin":false},"body":"PLEASE DONT MERGE BEFORE DEVELOPERS TEST IT. AND MORE COMMENTS NEED TO BE ADDED.\r\n\r\nThis Pull Request has done the following things:\r\n\r\n* Supports to preload small audio files and cache them with PCM data buffer\r\n* MP3/Ogg/... files are decoded to PCM data by OpenSLES API\r\n* Decoded PCM buffer data matches the best sample rate & buffer size in frames of device by using resampling source code in Android Source (Android 6.0, platform/frameworks/av)\r\n* Big refactoring for the implementation of AudioEngineImpl for Android, better class responsibility\r\n* There is a few TODOs need to be done, but this fix could be tested for latency now.\r\n\r\nPlease help to test it on the Android devices which have low performance. Thanks :)\r\n\r\n","created_at":"2016-06-17T09:52:04Z","updated_at":"2016-06-21T15:33:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"13cd046ab457d49a403db5b234be54c5dc800625","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cocos2d/cocos2d-x/pulls/15875/commits","review_comments_url":"https://api.github.com/repos/cocos2d/cocos2d-x/pulls/15875/comments","review_comment_url":"https://api.github.com/repos/cocos2d/cocos2d-x/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/15875/comments","statuses_url":"https://api.github.com/repos/cocos2d/cocos2d-x/statuses/fd63f420838391f0f7bf02ce8ed765e06e3564bb","head":{"label":"dumganhar:audio-latency-fix","ref":"audio-latency-fix","sha":"fd63f420838391f0f7bf02ce8ed765e06e3564bb","user":{"login":"dumganhar","id":493372,"avatar_url":"https://avatars.githubusercontent.com/u/493372?v=3","gravatar_id":"","url":"https://api.github.com/users/dumganhar","html_url":"https://github.com/dumganhar","followers_url":"https://api.github.com/users/dumganhar/followers","following_url":"https://api.github.com/users/dumganhar/following{/other_user}","gists_url":"https://api.github.com/users/dumganhar/gists{/gist_id}","starred_url":"https://api.github.com/users/dumganhar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dumganhar/subscriptions","organizations_url":"https://api.github.com/users/dumganhar/orgs","repos_url":"https://api.github.com/users/dumganhar/repos","events_url":"https://api.github.com/users/dumganhar/events{/privacy}","received_events_url":"https://api.github.com/users/dumganhar/received_events","type":"User","site_admin":false},"repo":{"id":2412853,"name":"cocos2d-x","full_name":"dumganhar/cocos2d-x","owner":{"login":"dumganhar","id":493372,"avatar_url":"https://avatars.githubusercontent.com/u/493372?v=3","gravatar_id":"","url":"https://api.github.com/users/dumganhar","html_url":"https://github.com/dumganhar","followers_url":"https://api.github.com/users/dumganhar/followers","following_url":"https://api.github.com/users/dumganhar/following{/other_user}","gists_url":"https://api.github.com/users/dumganhar/gists{/gist_id}","starred_url":"https://api.github.com/users/dumganhar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dumganhar/subscriptions","organizations_url":"https://api.github.com/users/dumganhar/orgs","repos_url":"https://api.github.com/users/dumganhar/repos","events_url":"https://api.github.com/users/dumganhar/events{/privacy}","received_events_url":"https://api.github.com/users/dumganhar/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dumganhar/cocos2d-x","description":"Port of cocos2d-iphone in C++","fork":true,"url":"https://api.github.com/repos/dumganhar/cocos2d-x","forks_url":"https://api.github.com/repos/dumganhar/cocos2d-x/forks","keys_url":"https://api.github.com/repos/dumganhar/cocos2d-x/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dumganhar/cocos2d-x/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dumganhar/cocos2d-x/teams","hooks_url":"https://api.github.com/repos/dumganhar/cocos2d-x/hooks","issue_events_url":"https://api.github.com/repos/dumganhar/cocos2d-x/issues/events{/number}","events_url":"https://api.github.com/repos/dumganhar/cocos2d-x/events","assignees_url":"https://api.github.com/repos/dumganhar/cocos2d-x/assignees{/user}","branches_url":"https://api.github.com/repos/dumganhar/cocos2d-x/branches{/branch}","tags_url":"https://api.github.com/repos/dumganhar/cocos2d-x/tags","blobs_url":"https://api.github.com/repos/dumganhar/cocos2d-x/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dumganhar/cocos2d-x/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dumganhar/cocos2d-x/git/refs{/sha}","trees_url":"https://api.github.com/repos/dumganhar/cocos2d-x/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dumganhar/cocos2d-x/statuses/{sha}","languages_url":"https://api.github.com/repos/dumganhar/cocos2d-x/languages","stargazers_url":"https://api.github.com/repos/dumganhar/cocos2d-x/stargazers","contributors_url":"https://api.github.com/repos/dumganhar/cocos2d-x/contributors","subscribers_url":"https://api.github.com/repos/dumganhar/cocos2d-x/subscribers","subscription_url":"https://api.github.com/repos/dumganhar/cocos2d-x/subscription","commits_url":"https://api.github.com/repos/dumganhar/cocos2d-x/commits{/sha}","git_commits_url":"https://api.github.com/repos/dumganhar/cocos2d-x/git/commits{/sha}","comments_url":"https://api.github.com/repos/dumganhar/cocos2d-x/comments{/number}","issue_comment_url":"https://api.github.com/repos/dumganhar/cocos2d-x/issues/comments{/number}","contents_url":"https://api.github.com/repos/dumganhar/cocos2d-x/contents/{+path}","compare_url":"https://api.github.com/repos/dumganhar/cocos2d-x/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dumganhar/cocos2d-x/merges","archive_url":"https://api.github.com/repos/dumganhar/cocos2d-x/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dumganhar/cocos2d-x/downloads","issues_url":"https://api.github.com/repos/dumganhar/cocos2d-x/issues{/number}","pulls_url":"https://api.github.com/repos/dumganhar/cocos2d-x/pulls{/number}","milestones_url":"https://api.github.com/repos/dumganhar/cocos2d-x/milestones{/number}","notifications_url":"https://api.github.com/repos/dumganhar/cocos2d-x/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dumganhar/cocos2d-x/labels{/name}","releases_url":"https://api.github.com/repos/dumganhar/cocos2d-x/releases{/id}","deployments_url":"https://api.github.com/repos/dumganhar/cocos2d-x/deployments","created_at":"2011-09-19T03:20:38Z","updated_at":"2016-06-14T02:13:44Z","pushed_at":"2016-06-21T07:37:09Z","git_url":"git://github.com/dumganhar/cocos2d-x.git","ssh_url":"git@github.com:dumganhar/cocos2d-x.git","clone_url":"https://github.com/dumganhar/cocos2d-x.git","svn_url":"https://github.com/dumganhar/cocos2d-x","homepage":"http://www.cocos2d-x.org","size":992817,"stargazers_count":11,"watchers_count":11,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":0,"forks":9,"open_issues":0,"watchers":11,"default_branch":"v3"}},"base":{"label":"cocos2d:v3","ref":"v3","sha":"f9988cad8e98b8716778ae062e938d79c2678d96","user":{"login":"cocos2d","id":234324,"avatar_url":"https://avatars.githubusercontent.com/u/234324?v=3","gravatar_id":"","url":"https://api.github.com/users/cocos2d","html_url":"https://github.com/cocos2d","followers_url":"https://api.github.com/users/cocos2d/followers","following_url":"https://api.github.com/users/cocos2d/following{/other_user}","gists_url":"https://api.github.com/users/cocos2d/gists{/gist_id}","starred_url":"https://api.github.com/users/cocos2d/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cocos2d/subscriptions","organizations_url":"https://api.github.com/users/cocos2d/orgs","repos_url":"https://api.github.com/users/cocos2d/repos","events_url":"https://api.github.com/users/cocos2d/events{/privacy}","received_events_url":"https://api.github.com/users/cocos2d/received_events","type":"Organization","site_admin":false},"repo":{"id":1093228,"name":"cocos2d-x","full_name":"cocos2d/cocos2d-x","owner":{"login":"cocos2d","id":234324,"avatar_url":"https://avatars.githubusercontent.com/u/234324?v=3","gravatar_id":"","url":"https://api.github.com/users/cocos2d","html_url":"https://github.com/cocos2d","followers_url":"https://api.github.com/users/cocos2d/followers","following_url":"https://api.github.com/users/cocos2d/following{/other_user}","gists_url":"https://api.github.com/users/cocos2d/gists{/gist_id}","starred_url":"https://api.github.com/users/cocos2d/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cocos2d/subscriptions","organizations_url":"https://api.github.com/users/cocos2d/orgs","repos_url":"https://api.github.com/users/cocos2d/repos","events_url":"https://api.github.com/users/cocos2d/events{/privacy}","received_events_url":"https://api.github.com/users/cocos2d/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cocos2d/cocos2d-x","description":"cocos2d-x for C++","fork":false,"url":"https://api.github.com/repos/cocos2d/cocos2d-x","forks_url":"https://api.github.com/repos/cocos2d/cocos2d-x/forks","keys_url":"https://api.github.com/repos/cocos2d/cocos2d-x/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cocos2d/cocos2d-x/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cocos2d/cocos2d-x/teams","hooks_url":"https://api.github.com/repos/cocos2d/cocos2d-x/hooks","issue_events_url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/events{/number}","events_url":"https://api.github.com/repos/cocos2d/cocos2d-x/events","assignees_url":"https://api.github.com/repos/cocos2d/cocos2d-x/assignees{/user}","branches_url":"https://api.github.com/repos/cocos2d/cocos2d-x/branches{/branch}","tags_url":"https://api.github.com/repos/cocos2d/cocos2d-x/tags","blobs_url":"https://api.github.com/repos/cocos2d/cocos2d-x/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cocos2d/cocos2d-x/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cocos2d/cocos2d-x/git/refs{/sha}","trees_url":"https://api.github.com/repos/cocos2d/cocos2d-x/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cocos2d/cocos2d-x/statuses/{sha}","languages_url":"https://api.github.com/repos/cocos2d/cocos2d-x/languages","stargazers_url":"https://api.github.com/repos/cocos2d/cocos2d-x/stargazers","contributors_url":"https://api.github.com/repos/cocos2d/cocos2d-x/contributors","subscribers_url":"https://api.github.com/repos/cocos2d/cocos2d-x/subscribers","subscription_url":"https://api.github.com/repos/cocos2d/cocos2d-x/subscription","commits_url":"https://api.github.com/repos/cocos2d/cocos2d-x/commits{/sha}","git_commits_url":"https://api.github.com/repos/cocos2d/cocos2d-x/git/commits{/sha}","comments_url":"https://api.github.com/repos/cocos2d/cocos2d-x/comments{/number}","issue_comment_url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/comments{/number}","contents_url":"https://api.github.com/repos/cocos2d/cocos2d-x/contents/{+path}","compare_url":"https://api.github.com/repos/cocos2d/cocos2d-x/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cocos2d/cocos2d-x/merges","archive_url":"https://api.github.com/repos/cocos2d/cocos2d-x/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cocos2d/cocos2d-x/downloads","issues_url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues{/number}","pulls_url":"https://api.github.com/repos/cocos2d/cocos2d-x/pulls{/number}","milestones_url":"https://api.github.com/repos/cocos2d/cocos2d-x/milestones{/number}","notifications_url":"https://api.github.com/repos/cocos2d/cocos2d-x/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cocos2d/cocos2d-x/labels{/name}","releases_url":"https://api.github.com/repos/cocos2d/cocos2d-x/releases{/id}","deployments_url":"https://api.github.com/repos/cocos2d/cocos2d-x/deployments","created_at":"2010-11-18T23:17:00Z","updated_at":"2016-06-21T12:51:58Z","pushed_at":"2016-06-21T11:50:30Z","git_url":"git://github.com/cocos2d/cocos2d-x.git","ssh_url":"git@github.com:cocos2d/cocos2d-x.git","clone_url":"https://github.com/cocos2d/cocos2d-x.git","svn_url":"https://github.com/cocos2d/cocos2d-x","homepage":"http://www.cocos2d-x.org","size":1516499,"stargazers_count":8259,"watchers_count":8259,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5493,"mirror_url":null,"open_issues_count":1064,"forks":5493,"open_issues":1064,"watchers":8259,"default_branch":"v3"}},"_links":{"self":{"href":"https://api.github.com/repos/cocos2d/cocos2d-x/pulls/15875"},"html":{"href":"https://github.com/cocos2d/cocos2d-x/pull/15875"},"issue":{"href":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/15875"},"comments":{"href":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/15875/comments"},"review_comments":{"href":"https://api.github.com/repos/cocos2d/cocos2d-x/pulls/15875/comments"},"review_comment":{"href":"https://api.github.com/repos/cocos2d/cocos2d-x/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cocos2d/cocos2d-x/pulls/15875/commits"},"statuses":{"href":"https://api.github.com/repos/cocos2d/cocos2d-x/statuses/fd63f420838391f0f7bf02ce8ed765e06e3564bb"}}}}
{"actor":{"display_login":"j-jorge"}}