audio: Calculate proper channel count for bytes per frame

On an SSR, write progress is simulated for PCM tracks
by incrementing bytes written and sleeping for the duration
of the buffer sent from AF. Fix calculation of bytes per
frame used for the increment.

Change-Id: I69a5694ec0e45a0fa7d94416620afea3ad170adb
CRs-Fixed: 1058402
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index b617407..9894446 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -2688,8 +2688,11 @@
             /* increase written size during SSR to avoid mismatch
              * with the written frames count in AF
              */
-            if (audio_bytes_per_sample(out->format) != 0)
-                out->written += bytes / (out->config.channels * audio_bytes_per_sample(out->format));
+            // bytes per frame
+            size_t bpf = audio_bytes_per_sample(out->format) *
+                         audio_channel_count_from_out_mask(out->channel_mask);
+            if (bpf != 0)
+                out->written += bytes / bpf;
             ALOGD(" %s: sound card is not active/SSR state", __func__);
             ret= -EIO;
             goto exit;
@@ -3653,7 +3656,12 @@
         else if (config->channel_mask) {
             out->channel_mask = config->channel_mask;
             config->offload_info.channel_mask = config->channel_mask;
+        } else {
+            ALOGE("out->channel_mask not set for OFFLOAD/DIRECT_PCM");
+            ret = -EINVAL;
+            goto error_open;
         }
+
         format = out->format = config->offload_info.format;
         out->sample_rate = config->offload_info.sample_rate;