)]}'
{
  "commit": "c4e90131d8cdb2bef34bc1edea784efe36bd3c86",
  "tree": "b36a42baf632c8aecdfc55203b0a384b8cdf83e4",
  "parents": [
    "4333c308afa4a695fd8f444d308b794cad656a6e"
  ],
  "author": {
    "name": "Kevin Rocard",
    "email": "krocard@google.com",
    "time": "Wed Sep 18 11:24:52 2019 +0100"
  },
  "committer": {
    "name": "Eric Laurent",
    "email": "elaurent@google.com",
    "time": "Mon Nov 11 17:10:42 2019 +0000"
  },
  "message": "Fix secondary output under\u0026over run\n\nThere were three issues with the implementation\nof Audio Playback Capture patches on secondary outputs.\n\n1) Patch tracks were always forced to be ready, even if there were not\nenough audio to be played. That led to playing partial buffers if the\nsource output had smaller (time wise) buffer than the secondary output.\n\nThis is fixed by avoiding setting CBLK_FORCEREADY on every buffer push\nfrom the primary output thread.\n\n2) After 1 is fixed, the patch tracks now behave like regular (non fast)\ntracks. This means that the track only starts when it is full.\nThat leads to overrun on startup as the primary and secondary outputs\nusually do not have the same write period.\n\nWhat makes the issue worst is that Remote submix has a fixed buffer in bytes,\nso its write period changes depending on sample rate contrary to the\nprimary HAL which pulls with fixed time periods (usually 20/40ms).\n\nThis patch solution is to introduce a ready threshold. The track will be\nconsidered ready to be active if there are more than frames in its buffer.\n\nTo avoid changing previous latency behaviour except for APC,\nlegacy tracks have this threshold set to their buffer size and\nnon APC patch tracks have it set to 1, similar to setting\nCBLK_FORCEREADY.\n\n3) The patch track buffer size calculation of the patch track did not take\ninto account primary and secondary output could be of different sampling\nrate.\nThis mean that the patch track buffer was usually too small as the\nsecondary output usually had smaller sampling rate (Live caption\nrequests 16kHz) than the track (music usually plays in 48kHz).\nThis made the two problems even worst.\n\nThis was easily fixed by scaling the buffer size with each side sample rate.\n\nBug: 136691300\nTest: play audio\n      adb shell audiorecorder  --target /data/file1.raw\n      # Check that the recorded file has no underrun\nChange-Id: Ib2846b2827afd1b953d4a25acb18c7cadf57cd3e\nSigned-off-by: Kevin Rocard \u003ckrocard@google.com\u003e\n(cherry picked from commit 01c7d9ee1b170a516e20b9c7aad3f9d1db982c55)\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "d38190d95ec37152bac2296e513eceb2e69c9adb",
      "old_mode": 33188,
      "old_path": "services/audioflinger/AudioFlinger.cpp",
      "new_id": "8bbdc69c0ffa8237ff5be5d1b469d9fc27070b5a",
      "new_mode": 33188,
      "new_path": "services/audioflinger/AudioFlinger.cpp"
    },
    {
      "type": "modify",
      "old_id": "a093893fac2dfd5becfbec28fee0da5bd9b198e5",
      "old_mode": 33188,
      "old_path": "services/audioflinger/PlaybackTracks.h",
      "new_id": "17adba5bd541f7d7d43a864a4285df1c45ad8952",
      "new_mode": 33188,
      "new_path": "services/audioflinger/PlaybackTracks.h"
    },
    {
      "type": "modify",
      "old_id": "2a5a713ca3cce0270f51ccc7ed58e930ea582051",
      "old_mode": 33188,
      "old_path": "services/audioflinger/Tracks.cpp",
      "new_id": "51e57b51cb7535c1e962cf6c55b582cdcc54d2fc",
      "new_mode": 33188,
      "new_path": "services/audioflinger/Tracks.cpp"
    }
  ]
}
