You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/11/28 07:41:25 UTC

[GitHub] [nuttx-apps] qiaohaijiao opened a new pull request, #1440: nxplayer: add mp3 offload playback demo

qiaohaijiao opened a new pull request, #1440:
URL: https://github.com/apache/nuttx-apps/pull/1440

   ## Summary
   nxplayer: add mp3 offload playback demo.
   
   only parse ID3v2 header simple.
   usage:
       nxplayer
       device pcm0p
       play /stream/1.mp3
   
   ## Impact
   nxplayer
   
   ## Testing
   VELA
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx-apps] qiaohaijiao commented on a diff in pull request #1440: nxplayer: add mp3 offload playback demo

Posted by GitBox <gi...@apache.org>.
qiaohaijiao commented on code in PR #1440:
URL: https://github.com/apache/nuttx-apps/pull/1440#discussion_r1037793939


##########
system/nxplayer/nxplayer_mp3.c:
##########
@@ -0,0 +1,321 @@
+/****************************************************************************
+ * apps/system/nxplayer/nxplayer_mp3.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <nuttx/audio/audio.h>
+
+#include "system/nxplayer.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ID3V2_BIT_MASK 0x7F
+
+/****************************************************************************
+ * Private Type Declarations
+ ****************************************************************************/
+
+const static uint16_t g_mpa_freq_tab[3] =
+{
+  44100, 48000, 32000
+};
+
+const static uint16_t g_mpa_bitrate_tab[2][3][15] =
+{
+  {
+    {
+      0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448
+    },
+    {
+      0, 32, 48, 56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320, 384
+    },
+    {
+      0, 32, 40, 48,  56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320
+    }
+  },
+  {
+    {
+      0, 32, 48, 56,  64,  80,  96, 112, 128, 144, 160, 176, 192, 224, 256
+    },
+    {
+      0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160
+    },
+    {
+      0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160
+    }
+  }
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int nxplayer_check_mpeg(uint32_t header)
+{
+  int ret = -EINVAL;
+
+  /* header */
+
+  if ((header & 0xffe00000) != 0xffe00000)
+    {
+      return ret;
+    }
+
+  /* version check */
+
+  if ((header & (3 << 19)) == 1 << 19)
+    {
+      return ret;
+    }
+
+  /* layer check */
+
+  if ((header & (3 << 17)) == 0)
+    {
+      return ret;
+    }
+
+  /* bit rate */
+
+  if ((header & (0xf << 12)) == 0xf << 12)
+    {
+      return ret;
+    }
+
+  /* frequency */
+
+  if ((header & (3 << 10)) == 3 << 10)
+    {
+      return ret;
+    }
+
+  return 0;
+}
+
+static int nxplayer_parse_mpeg(uint32_t header, FAR uint32_t *samplerate,
+                               FAR uint8_t *chans, FAR uint8_t *bps)
+{
+  int sample_rate;
+  int frame_size;
+  int padding;
+  int mpeg25;
+  int sr_idx;
+  int br_idx;
+  int layer;
+  int mode;
+  int lsf;
+  int ret;
+
+  ret = nxplayer_check_mpeg(header);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  if (header & (1 << 20))
+    {
+      lsf = (header & (1 << 19)) ? 0 : 1;
+      mpeg25 = 0;
+    }
+  else
+    {
+      lsf = 1;
+      mpeg25 = 1;
+    }
+
+  layer   = 4 - ((header >> 17) & 3);
+  br_idx  = (header >> 12) & 0xf;
+  sr_idx  = (header >> 10) & 3;
+  padding = (header >> 9) & 1;
+  mode    = (header >> 6) & 3;
+
+  if (sr_idx >= sizeof(g_mpa_freq_tab) / sizeof(g_mpa_freq_tab[0]) ||
+      br_idx >= 0xf)
+    {
+      return -EINVAL;
+    }
+
+  sample_rate = g_mpa_freq_tab[sr_idx] >> (lsf + mpeg25);
+
+  if (br_idx != 0)
+    {
+      frame_size = g_mpa_bitrate_tab[lsf][layer - 1][br_idx];
+
+      switch (layer)
+        {
+          case 1:
+            frame_size = (frame_size * 12000) / sample_rate;
+            frame_size = (frame_size + padding) * 4;
+            break;
+
+          case 2:
+            frame_size = (frame_size * 144000) / sample_rate;
+            frame_size += padding;
+            break;
+
+          default:
+          case 3:
+            frame_size = (frame_size * 144000) / (sample_rate << lsf);
+            frame_size += padding;
+            break;
+        }
+    }
+  else
+    {
+      /* if no frame size computed, signal it */
+
+      return -EINVAL;
+    }
+
+  if (samplerate)
+    {
+      *samplerate = sample_rate;
+    }
+
+  if (chans)
+    {
+      *chans = mode == 3 ? 1 : 2;
+    }
+
+  if (bps)
+    {
+      *bps = 16;
+    }
+
+  return frame_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxplayer_parse_mp3
+ *
+ *   nxplayer_parse_mp3() parse mp3 header, get samplerate, channels, bps.
+ *
+ ****************************************************************************/
+
+int nxplayer_parse_mp3(int fd, FAR uint32_t *samplerate,
+                       FAR uint8_t *chans, FAR uint8_t *bps)
+{
+  uint32_t mpa_header;
+  uint8_t buffer[10];
+  off_t position;
+  int ret;
+
+  if (fd == -1)
+    {
+      return -EINVAL;
+    }
+
+  read(fd, buffer, sizeof(buffer));
+  position = (buffer[6] & ID3V2_BIT_MASK) * 0x200000 +
+             (buffer[7] & ID3V2_BIT_MASK) * 0x4000 +
+             (buffer[8] & ID3V2_BIT_MASK) * 0x80 +
+             (buffer[9] & ID3V2_BIT_MASK) +
+             sizeof(buffer);
+
+  lseek(fd, position, SEEK_SET);
+
+  read(fd, buffer, 4);
+  mpa_header = buffer[0] << 24 |
+               buffer[1] << 16 |
+               buffer[2] << 8  |
+               buffer[3];
+
+  ret = nxplayer_parse_mpeg(mpa_header, samplerate, chans, bps);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  lseek(fd, position, SEEK_SET);
+  return OK;
+}
+
+/****************************************************************************
+ * Name: nxplayer_fill_mp3
+ *
+ *   nxplayer_fill_mp3 fill mp3 data into apb buffer.
+ *
+ ****************************************************************************/
+
+int nxplayer_fill_mp3(int fd, FAR struct ap_buffer_s *apb)
+{
+  uint32_t mpa_header;
+  uint8_t header[16];
+  int h_size;
+  int b_size;
+  off_t pos;
+  int size;
+  int ret;
+
+  if (fd == -1)
+    {
+      return -EINVAL;
+    }
+
+  h_size = 4;

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx-apps] qiaohaijiao commented on a diff in pull request #1440: nxplayer: add mp3 offload playback demo

Posted by GitBox <gi...@apache.org>.
qiaohaijiao commented on code in PR #1440:
URL: https://github.com/apache/nuttx-apps/pull/1440#discussion_r1035584920


##########
system/nxplayer/nxplayer.c:
##########
@@ -121,6 +125,14 @@ static const struct nxplayer_ext_fmt_s g_known_ext[] =
 
 static const int g_known_ext_count = sizeof(g_known_ext) /
                     sizeof(struct nxplayer_ext_fmt_s);
+
+static const struct nxplayer_dec_ops_s g_dec_mp3 =

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx-apps] xiaoxiang781216 commented on a diff in pull request #1440: nxplayer: add mp3 offload playback demo

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #1440:
URL: https://github.com/apache/nuttx-apps/pull/1440#discussion_r1037884402


##########
system/nxplayer/nxplayer.c:
##########
@@ -121,6 +131,27 @@ static const struct nxplayer_ext_fmt_s g_known_ext[] =
 
 static const int g_known_ext_count = sizeof(g_known_ext) /
                     sizeof(struct nxplayer_ext_fmt_s);
+
+static const struct nxplayer_dec_ops_s g_dec_mp3 =
+{
+  AUDIO_FMT_MP3,
+  nxplayer_parse_mp3,
+  nxplayer_fill_mp3
+};
+
+static const struct nxplayer_dec_ops_s g_dec_pcm =
+{
+  AUDIO_FMT_PCM,
+  NULL,
+  nxplayer_fill_pcm
+};
+
+static const struct nxplayer_dec_ops_s g_dec_s[] =

Review Comment:
   let fill the array in place



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx-apps] xiaoxiang781216 commented on a diff in pull request #1440: nxplayer: add mp3 offload playback demo

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #1440:
URL: https://github.com/apache/nuttx-apps/pull/1440#discussion_r1034249940


##########
include/system/nxplayer.h:
##########
@@ -39,6 +39,14 @@
  * Public Type Declarations
  ****************************************************************************/
 
+struct nxplayer_dec_ops_s
+{
+  int format;
+  int (*pre_parse)(int fd, uint32_t *samplerate,
+                   uint8_t *chans, uint8_t *bps);

Review Comment:
   add CODE and FAR



##########
system/nxplayer/nxplayer_offload.c:
##########
@@ -0,0 +1,321 @@
+/****************************************************************************
+ * apps/system/nxplayer/nxplayer_offload.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <nuttx/audio/audio.h>
+
+#include "system/nxplayer.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ID3V2_BIT_MASK 0x7F
+
+/****************************************************************************
+ * Private Type Declarations
+ ****************************************************************************/
+
+const static uint16_t mpa_freq_tab[3] =

Review Comment:
   ```suggestion
   const static uint16_t g_mpa_freq_tab[3] =
   ```
   and g_ prefix for all global variables



##########
system/nxplayer/nxplayer_offload.c:
##########
@@ -0,0 +1,321 @@
+/****************************************************************************
+ * apps/system/nxplayer/nxplayer_offload.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <nuttx/audio/audio.h>
+
+#include "system/nxplayer.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ID3V2_BIT_MASK 0x7F
+
+/****************************************************************************
+ * Private Type Declarations
+ ****************************************************************************/
+
+const static uint16_t mpa_freq_tab[3] =
+{
+  44100, 48000, 32000
+};
+
+const static uint16_t mpa_bitrate_tab[2][3][15] =
+{
+  {
+    {
+      0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448
+    },
+    {
+      0, 32, 48, 56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320, 384
+    },
+    {
+      0, 32, 40, 48,  56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320
+    }
+  },
+  {
+    {
+      0, 32, 48, 56,  64,  80,  96, 112, 128, 144, 160, 176, 192, 224, 256
+    },
+    {
+      0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160
+    },
+    {
+      0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160
+    }
+  }
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int nxplayer_check_mpeg(uint32_t header)
+{
+  int ret = -EINVAL;
+
+  /* header */
+
+  if ((header & 0xffe00000) != 0xffe00000)
+    {
+      return ret;
+    }
+
+  /* version check */
+
+  if ((header & (3 << 19)) == 1 << 19)
+    {
+      return ret;
+    }
+
+  /* layer check */
+
+  if ((header & (3 << 17)) == 0)
+    {
+      return ret;
+    }
+
+  /* bit rate */
+
+  if ((header & (0xf << 12)) == 0xf << 12)
+    {
+      return ret;
+    }
+
+  /* frequency */
+
+  if ((header & (3 << 10)) == 3 << 10)
+    {
+      return ret;
+    }
+
+  return 0;
+}
+
+static int nxplayer_parse_mpeg(uint32_t header, uint32_t *samplerate,

Review Comment:
   add FAR



##########
include/system/nxplayer.h:
##########
@@ -39,6 +39,14 @@
  * Public Type Declarations
  ****************************************************************************/
 
+struct nxplayer_dec_ops_s
+{
+  int format;
+  int (*pre_parse)(int fd, uint32_t *samplerate,
+                   uint8_t *chans, uint8_t *bps);
+  int (*fill_data)(int fd, FAR struct ap_buffer_s *apb);

Review Comment:
   add CODE



##########
system/nxplayer/nxplayer.c:
##########
@@ -1877,6 +1900,18 @@ static int nxplayer_playinternal(FAR struct nxplayer_s *pplayer,
       goto err_out_nodev;
     }
 
+  if (filefmt == AUDIO_FMT_MP3)
+    {
+      pplayer->ops = &g_dec_mp3;
+      ret = pplayer->ops->pre_parse(pplayer->fd, &samprate,
+                                    &nchannels, &bpsamp);
+      if (ret < 0)
+        {
+          ret = -ENOSYS;

Review Comment:
   remove



##########
system/nxplayer/nxplayer.c:
##########
@@ -121,6 +125,14 @@ static const struct nxplayer_ext_fmt_s g_known_ext[] =
 
 static const int g_known_ext_count = sizeof(g_known_ext) /
                     sizeof(struct nxplayer_ext_fmt_s);
+
+static const struct nxplayer_dec_ops_s g_dec_mp3 =

Review Comment:
   can we make the similar adjust for .wav files?



##########
system/nxplayer/nxplayer_offload.c:
##########
@@ -0,0 +1,321 @@
+/****************************************************************************
+ * apps/system/nxplayer/nxplayer_offload.c

Review Comment:
   should we name the file nxplayer_offload_mp3.c?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx-apps] qiaohaijiao commented on a diff in pull request #1440: nxplayer: add mp3 offload playback demo

Posted by GitBox <gi...@apache.org>.
qiaohaijiao commented on code in PR #1440:
URL: https://github.com/apache/nuttx-apps/pull/1440#discussion_r1035584748


##########
system/nxplayer/nxplayer_offload.c:
##########
@@ -0,0 +1,321 @@
+/****************************************************************************
+ * apps/system/nxplayer/nxplayer_offload.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <nuttx/audio/audio.h>
+
+#include "system/nxplayer.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ID3V2_BIT_MASK 0x7F
+
+/****************************************************************************
+ * Private Type Declarations
+ ****************************************************************************/
+
+const static uint16_t mpa_freq_tab[3] =
+{
+  44100, 48000, 32000
+};
+
+const static uint16_t mpa_bitrate_tab[2][3][15] =
+{
+  {
+    {
+      0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448
+    },
+    {
+      0, 32, 48, 56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320, 384
+    },
+    {
+      0, 32, 40, 48,  56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320
+    }
+  },
+  {
+    {
+      0, 32, 48, 56,  64,  80,  96, 112, 128, 144, 160, 176, 192, 224, 256
+    },
+    {
+      0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160
+    },
+    {
+      0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160
+    }
+  }
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int nxplayer_check_mpeg(uint32_t header)
+{
+  int ret = -EINVAL;
+
+  /* header */
+
+  if ((header & 0xffe00000) != 0xffe00000)
+    {
+      return ret;
+    }
+
+  /* version check */
+
+  if ((header & (3 << 19)) == 1 << 19)
+    {
+      return ret;
+    }
+
+  /* layer check */
+
+  if ((header & (3 << 17)) == 0)
+    {
+      return ret;
+    }
+
+  /* bit rate */
+
+  if ((header & (0xf << 12)) == 0xf << 12)
+    {
+      return ret;
+    }
+
+  /* frequency */
+
+  if ((header & (3 << 10)) == 3 << 10)
+    {
+      return ret;
+    }
+
+  return 0;
+}
+
+static int nxplayer_parse_mpeg(uint32_t header, uint32_t *samplerate,

Review Comment:
   done



##########
system/nxplayer/nxplayer_offload.c:
##########
@@ -0,0 +1,321 @@
+/****************************************************************************
+ * apps/system/nxplayer/nxplayer_offload.c

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx-apps] qiaohaijiao commented on a diff in pull request #1440: nxplayer: add mp3 offload playback demo

Posted by GitBox <gi...@apache.org>.
qiaohaijiao commented on code in PR #1440:
URL: https://github.com/apache/nuttx-apps/pull/1440#discussion_r1035584500


##########
system/nxplayer/nxplayer.c:
##########
@@ -1877,6 +1900,18 @@ static int nxplayer_playinternal(FAR struct nxplayer_s *pplayer,
       goto err_out_nodev;
     }
 
+  if (filefmt == AUDIO_FMT_MP3)
+    {
+      pplayer->ops = &g_dec_mp3;
+      ret = pplayer->ops->pre_parse(pplayer->fd, &samprate,
+                                    &nchannels, &bpsamp);
+      if (ret < 0)
+        {
+          ret = -ENOSYS;

Review Comment:
   done



##########
system/nxplayer/nxplayer_offload.c:
##########
@@ -0,0 +1,321 @@
+/****************************************************************************
+ * apps/system/nxplayer/nxplayer_offload.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <nuttx/audio/audio.h>
+
+#include "system/nxplayer.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ID3V2_BIT_MASK 0x7F
+
+/****************************************************************************
+ * Private Type Declarations
+ ****************************************************************************/
+
+const static uint16_t mpa_freq_tab[3] =

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx-apps] qiaohaijiao commented on a diff in pull request #1440: nxplayer: add mp3 offload playback demo

Posted by GitBox <gi...@apache.org>.
qiaohaijiao commented on code in PR #1440:
URL: https://github.com/apache/nuttx-apps/pull/1440#discussion_r1037821686


##########
system/nxplayer/nxplayer.c:
##########
@@ -121,6 +131,27 @@ static const struct nxplayer_ext_fmt_s g_known_ext[] =
 
 static const int g_known_ext_count = sizeof(g_known_ext) /
                     sizeof(struct nxplayer_ext_fmt_s);
+
+static const struct nxplayer_dec_ops_s g_dec_mp3 =
+{
+  AUDIO_FMT_MP3,
+  nxplayer_parse_mp3,
+  nxplayer_fill_mp3
+};
+
+static const struct nxplayer_dec_ops_s g_dec_pcm =
+{
+  AUDIO_FMT_PCM,
+  NULL,
+  nxplayer_fill_pcm
+};
+
+static const struct nxplayer_dec_ops_s g_dec_s[] =

Review Comment:
   hello pkarashchenko, 
   there is no copy, use the reference of g_dec_pcm or g_dec_mp3 in function `nxplayer_playinternal`.
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx-apps] xiaoxiang781216 commented on a diff in pull request #1440: nxplayer: add mp3 offload playback demo

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #1440:
URL: https://github.com/apache/nuttx-apps/pull/1440#discussion_r1036087441


##########
system/nxplayer/nxplayer.c:
##########
@@ -80,6 +80,12 @@ struct nxplayer_ext_fmt_s
 };
 #endif
 
+struct nxplayer_fmt_s

Review Comment:
   merge with nxplayer_dec_ops_s?



##########
include/system/nxplayer.h:
##########
@@ -39,6 +39,14 @@
  * Public Type Declarations
  ****************************************************************************/
 
+struct nxplayer_dec_ops_s
+{
+  int format;
+  int (*pre_parse)(int fd, uint32_t *samplerate,
+                   uint8_t *chans, uint8_t *bps);

Review Comment:
   but not add all



##########
system/nxplayer/Makefile:
##########
@@ -23,6 +23,8 @@ include $(APPDIR)/Make.defs
 # NxPlayer Library
 
 CSRCS     = nxplayer.c
+CSRCS    += nxplayer_offload_mp3.c
+CSRCS    += nxplayer_pcm.c

Review Comment:
   let's unify the name either nxplayer_[mp3|pcm].c  or nxplayer_offload_[mp3|pcm].c



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx-apps] xiaoxiang781216 commented on a diff in pull request #1440: nxplayer: add mp3 offload playback demo

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #1440:
URL: https://github.com/apache/nuttx-apps/pull/1440#discussion_r1037203702


##########
system/nxplayer/nxplayer_mp3.c:
##########
@@ -0,0 +1,321 @@
+/****************************************************************************
+ * apps/system/nxplayer/nxplayer_mp3.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <nuttx/audio/audio.h>
+
+#include "system/nxplayer.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ID3V2_BIT_MASK 0x7F
+
+/****************************************************************************
+ * Private Type Declarations
+ ****************************************************************************/
+
+const static uint16_t g_mpa_freq_tab[3] =
+{
+  44100, 48000, 32000
+};
+
+const static uint16_t g_mpa_bitrate_tab[2][3][15] =
+{
+  {
+    {
+      0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448
+    },
+    {
+      0, 32, 48, 56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320, 384
+    },
+    {
+      0, 32, 40, 48,  56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320
+    }
+  },
+  {
+    {
+      0, 32, 48, 56,  64,  80,  96, 112, 128, 144, 160, 176, 192, 224, 256
+    },
+    {
+      0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160
+    },
+    {
+      0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160
+    }
+  }
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int nxplayer_check_mpeg(uint32_t header)
+{
+  int ret = -EINVAL;
+
+  /* header */
+
+  if ((header & 0xffe00000) != 0xffe00000)
+    {
+      return ret;
+    }
+
+  /* version check */
+
+  if ((header & (3 << 19)) == 1 << 19)
+    {
+      return ret;
+    }
+
+  /* layer check */
+
+  if ((header & (3 << 17)) == 0)
+    {
+      return ret;
+    }
+
+  /* bit rate */
+
+  if ((header & (0xf << 12)) == 0xf << 12)
+    {
+      return ret;
+    }
+
+  /* frequency */
+
+  if ((header & (3 << 10)) == 3 << 10)
+    {
+      return ret;
+    }
+
+  return 0;
+}
+
+static int nxplayer_parse_mpeg(uint32_t header, FAR uint32_t *samplerate,
+                               FAR uint8_t *chans, FAR uint8_t *bps)
+{
+  int sample_rate;
+  int frame_size;
+  int padding;
+  int mpeg25;
+  int sr_idx;
+  int br_idx;
+  int layer;
+  int mode;
+  int lsf;
+  int ret;
+
+  ret = nxplayer_check_mpeg(header);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  if (header & (1 << 20))
+    {
+      lsf = (header & (1 << 19)) ? 0 : 1;
+      mpeg25 = 0;
+    }
+  else
+    {
+      lsf = 1;
+      mpeg25 = 1;
+    }
+
+  layer   = 4 - ((header >> 17) & 3);
+  br_idx  = (header >> 12) & 0xf;
+  sr_idx  = (header >> 10) & 3;
+  padding = (header >> 9) & 1;
+  mode    = (header >> 6) & 3;
+
+  if (sr_idx >= sizeof(g_mpa_freq_tab) / sizeof(g_mpa_freq_tab[0]) ||
+      br_idx >= 0xf)
+    {
+      return -EINVAL;
+    }
+
+  sample_rate = g_mpa_freq_tab[sr_idx] >> (lsf + mpeg25);
+
+  if (br_idx != 0)
+    {
+      frame_size = g_mpa_bitrate_tab[lsf][layer - 1][br_idx];
+
+      switch (layer)
+        {
+          case 1:
+            frame_size = (frame_size * 12000) / sample_rate;
+            frame_size = (frame_size + padding) * 4;
+            break;
+
+          case 2:
+            frame_size = (frame_size * 144000) / sample_rate;
+            frame_size += padding;
+            break;
+
+          default:
+          case 3:
+            frame_size = (frame_size * 144000) / (sample_rate << lsf);
+            frame_size += padding;
+            break;
+        }
+    }
+  else
+    {
+      /* if no frame size computed, signal it */
+
+      return -EINVAL;
+    }
+
+  if (samplerate)
+    {
+      *samplerate = sample_rate;
+    }
+
+  if (chans)
+    {
+      *chans = mode == 3 ? 1 : 2;
+    }
+
+  if (bps)
+    {
+      *bps = 16;
+    }
+
+  return frame_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxplayer_parse_mp3
+ *
+ *   nxplayer_parse_mp3() parse mp3 header, get samplerate, channels, bps.
+ *
+ ****************************************************************************/
+
+int nxplayer_parse_mp3(int fd, FAR uint32_t *samplerate,
+                       FAR uint8_t *chans, FAR uint8_t *bps)
+{
+  uint32_t mpa_header;
+  uint8_t buffer[10];
+  off_t position;
+  int ret;
+
+  if (fd == -1)
+    {
+      return -EINVAL;
+    }
+
+  read(fd, buffer, sizeof(buffer));
+  position = (buffer[6] & ID3V2_BIT_MASK) * 0x200000 +
+             (buffer[7] & ID3V2_BIT_MASK) * 0x4000 +
+             (buffer[8] & ID3V2_BIT_MASK) * 0x80 +
+             (buffer[9] & ID3V2_BIT_MASK) +
+             sizeof(buffer);
+
+  lseek(fd, position, SEEK_SET);
+
+  read(fd, buffer, 4);
+  mpa_header = buffer[0] << 24 |
+               buffer[1] << 16 |
+               buffer[2] << 8  |
+               buffer[3];
+
+  ret = nxplayer_parse_mpeg(mpa_header, samplerate, chans, bps);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  lseek(fd, position, SEEK_SET);
+  return OK;
+}
+
+/****************************************************************************
+ * Name: nxplayer_fill_mp3
+ *
+ *   nxplayer_fill_mp3 fill mp3 data into apb buffer.
+ *
+ ****************************************************************************/
+
+int nxplayer_fill_mp3(int fd, FAR struct ap_buffer_s *apb)
+{
+  uint32_t mpa_header;
+  uint8_t header[16];
+  int h_size;
+  int b_size;
+  off_t pos;
+  int size;
+  int ret;
+
+  if (fd == -1)

Review Comment:
   remove



##########
system/nxplayer/nxplayer_mp3.c:
##########
@@ -0,0 +1,321 @@
+/****************************************************************************
+ * apps/system/nxplayer/nxplayer_mp3.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <nuttx/audio/audio.h>
+
+#include "system/nxplayer.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ID3V2_BIT_MASK 0x7F
+
+/****************************************************************************
+ * Private Type Declarations
+ ****************************************************************************/
+
+const static uint16_t g_mpa_freq_tab[3] =
+{
+  44100, 48000, 32000
+};
+
+const static uint16_t g_mpa_bitrate_tab[2][3][15] =
+{
+  {
+    {
+      0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448
+    },
+    {
+      0, 32, 48, 56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320, 384
+    },
+    {
+      0, 32, 40, 48,  56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320
+    }
+  },
+  {
+    {
+      0, 32, 48, 56,  64,  80,  96, 112, 128, 144, 160, 176, 192, 224, 256
+    },
+    {
+      0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160
+    },
+    {
+      0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160
+    }
+  }
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int nxplayer_check_mpeg(uint32_t header)
+{
+  int ret = -EINVAL;
+
+  /* header */
+
+  if ((header & 0xffe00000) != 0xffe00000)
+    {
+      return ret;
+    }
+
+  /* version check */
+
+  if ((header & (3 << 19)) == 1 << 19)
+    {
+      return ret;
+    }
+
+  /* layer check */
+
+  if ((header & (3 << 17)) == 0)
+    {
+      return ret;
+    }
+
+  /* bit rate */
+
+  if ((header & (0xf << 12)) == 0xf << 12)
+    {
+      return ret;
+    }
+
+  /* frequency */
+
+  if ((header & (3 << 10)) == 3 << 10)
+    {
+      return ret;
+    }
+
+  return 0;
+}
+
+static int nxplayer_parse_mpeg(uint32_t header, FAR uint32_t *samplerate,
+                               FAR uint8_t *chans, FAR uint8_t *bps)
+{
+  int sample_rate;
+  int frame_size;
+  int padding;
+  int mpeg25;
+  int sr_idx;
+  int br_idx;
+  int layer;
+  int mode;
+  int lsf;
+  int ret;
+
+  ret = nxplayer_check_mpeg(header);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  if (header & (1 << 20))
+    {
+      lsf = (header & (1 << 19)) ? 0 : 1;
+      mpeg25 = 0;
+    }
+  else
+    {
+      lsf = 1;
+      mpeg25 = 1;
+    }
+
+  layer   = 4 - ((header >> 17) & 3);
+  br_idx  = (header >> 12) & 0xf;
+  sr_idx  = (header >> 10) & 3;
+  padding = (header >> 9) & 1;
+  mode    = (header >> 6) & 3;
+
+  if (sr_idx >= sizeof(g_mpa_freq_tab) / sizeof(g_mpa_freq_tab[0]) ||
+      br_idx >= 0xf)
+    {
+      return -EINVAL;
+    }
+
+  sample_rate = g_mpa_freq_tab[sr_idx] >> (lsf + mpeg25);
+
+  if (br_idx != 0)
+    {
+      frame_size = g_mpa_bitrate_tab[lsf][layer - 1][br_idx];
+
+      switch (layer)
+        {
+          case 1:
+            frame_size = (frame_size * 12000) / sample_rate;
+            frame_size = (frame_size + padding) * 4;
+            break;
+
+          case 2:
+            frame_size = (frame_size * 144000) / sample_rate;
+            frame_size += padding;
+            break;
+
+          default:
+          case 3:
+            frame_size = (frame_size * 144000) / (sample_rate << lsf);
+            frame_size += padding;
+            break;
+        }
+    }
+  else
+    {
+      /* if no frame size computed, signal it */
+
+      return -EINVAL;
+    }
+
+  if (samplerate)
+    {
+      *samplerate = sample_rate;
+    }
+
+  if (chans)
+    {
+      *chans = mode == 3 ? 1 : 2;
+    }
+
+  if (bps)
+    {
+      *bps = 16;
+    }
+
+  return frame_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxplayer_parse_mp3
+ *
+ *   nxplayer_parse_mp3() parse mp3 header, get samplerate, channels, bps.
+ *
+ ****************************************************************************/
+
+int nxplayer_parse_mp3(int fd, FAR uint32_t *samplerate,
+                       FAR uint8_t *chans, FAR uint8_t *bps)
+{
+  uint32_t mpa_header;
+  uint8_t buffer[10];
+  off_t position;
+  int ret;
+
+  if (fd == -1)
+    {
+      return -EINVAL;
+    }
+
+  read(fd, buffer, sizeof(buffer));
+  position = (buffer[6] & ID3V2_BIT_MASK) * 0x200000 +
+             (buffer[7] & ID3V2_BIT_MASK) * 0x4000 +
+             (buffer[8] & ID3V2_BIT_MASK) * 0x80 +
+             (buffer[9] & ID3V2_BIT_MASK) +
+             sizeof(buffer);
+
+  lseek(fd, position, SEEK_SET);
+
+  read(fd, buffer, 4);
+  mpa_header = buffer[0] << 24 |
+               buffer[1] << 16 |
+               buffer[2] << 8  |
+               buffer[3];
+
+  ret = nxplayer_parse_mpeg(mpa_header, samplerate, chans, bps);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  lseek(fd, position, SEEK_SET);
+  return OK;
+}
+
+/****************************************************************************
+ * Name: nxplayer_fill_mp3
+ *
+ *   nxplayer_fill_mp3 fill mp3 data into apb buffer.
+ *
+ ****************************************************************************/
+
+int nxplayer_fill_mp3(int fd, FAR struct ap_buffer_s *apb)
+{
+  uint32_t mpa_header;
+  uint8_t header[16];
+  int h_size;
+  int b_size;
+  off_t pos;
+  int size;
+  int ret;
+
+  if (fd == -1)
+    {
+      return -EINVAL;
+    }
+
+  h_size = 4;

Review Comment:
   merge to line 275



##########
system/nxplayer/nxplayer_mp3.c:
##########
@@ -0,0 +1,321 @@
+/****************************************************************************
+ * apps/system/nxplayer/nxplayer_mp3.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <nuttx/audio/audio.h>
+
+#include "system/nxplayer.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ID3V2_BIT_MASK 0x7F
+
+/****************************************************************************
+ * Private Type Declarations
+ ****************************************************************************/
+
+const static uint16_t g_mpa_freq_tab[3] =
+{
+  44100, 48000, 32000
+};
+
+const static uint16_t g_mpa_bitrate_tab[2][3][15] =
+{
+  {
+    {
+      0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448
+    },
+    {
+      0, 32, 48, 56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320, 384
+    },
+    {
+      0, 32, 40, 48,  56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320
+    }
+  },
+  {
+    {
+      0, 32, 48, 56,  64,  80,  96, 112, 128, 144, 160, 176, 192, 224, 256
+    },
+    {
+      0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160
+    },
+    {
+      0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160
+    }
+  }
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int nxplayer_check_mpeg(uint32_t header)
+{
+  int ret = -EINVAL;
+
+  /* header */
+
+  if ((header & 0xffe00000) != 0xffe00000)
+    {
+      return ret;

Review Comment:
   return -EINVAL directly and remove line 82



##########
system/nxplayer/nxplayer_mp3.c:
##########
@@ -0,0 +1,321 @@
+/****************************************************************************
+ * apps/system/nxplayer/nxplayer_mp3.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <nuttx/audio/audio.h>
+
+#include "system/nxplayer.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ID3V2_BIT_MASK 0x7F
+
+/****************************************************************************
+ * Private Type Declarations
+ ****************************************************************************/
+
+const static uint16_t g_mpa_freq_tab[3] =
+{
+  44100, 48000, 32000
+};
+
+const static uint16_t g_mpa_bitrate_tab[2][3][15] =
+{
+  {
+    {
+      0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448
+    },
+    {
+      0, 32, 48, 56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320, 384
+    },
+    {
+      0, 32, 40, 48,  56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320
+    }
+  },
+  {
+    {
+      0, 32, 48, 56,  64,  80,  96, 112, 128, 144, 160, 176, 192, 224, 256
+    },
+    {
+      0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160
+    },
+    {
+      0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160
+    }
+  }
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int nxplayer_check_mpeg(uint32_t header)
+{
+  int ret = -EINVAL;
+
+  /* header */
+
+  if ((header & 0xffe00000) != 0xffe00000)
+    {
+      return ret;
+    }
+
+  /* version check */
+
+  if ((header & (3 << 19)) == 1 << 19)
+    {
+      return ret;
+    }
+
+  /* layer check */
+
+  if ((header & (3 << 17)) == 0)
+    {
+      return ret;
+    }
+
+  /* bit rate */
+
+  if ((header & (0xf << 12)) == 0xf << 12)
+    {
+      return ret;
+    }
+
+  /* frequency */
+
+  if ((header & (3 << 10)) == 3 << 10)
+    {
+      return ret;
+    }
+
+  return 0;
+}
+
+static int nxplayer_parse_mpeg(uint32_t header, FAR uint32_t *samplerate,
+                               FAR uint8_t *chans, FAR uint8_t *bps)
+{
+  int sample_rate;
+  int frame_size;
+  int padding;
+  int mpeg25;
+  int sr_idx;
+  int br_idx;
+  int layer;
+  int mode;
+  int lsf;
+  int ret;
+
+  ret = nxplayer_check_mpeg(header);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  if (header & (1 << 20))
+    {
+      lsf = (header & (1 << 19)) ? 0 : 1;
+      mpeg25 = 0;
+    }
+  else
+    {
+      lsf = 1;
+      mpeg25 = 1;
+    }
+
+  layer   = 4 - ((header >> 17) & 3);
+  br_idx  = (header >> 12) & 0xf;
+  sr_idx  = (header >> 10) & 3;
+  padding = (header >> 9) & 1;
+  mode    = (header >> 6) & 3;
+
+  if (sr_idx >= sizeof(g_mpa_freq_tab) / sizeof(g_mpa_freq_tab[0]) ||
+      br_idx >= 0xf)
+    {
+      return -EINVAL;
+    }
+
+  sample_rate = g_mpa_freq_tab[sr_idx] >> (lsf + mpeg25);
+
+  if (br_idx != 0)
+    {
+      frame_size = g_mpa_bitrate_tab[lsf][layer - 1][br_idx];
+
+      switch (layer)
+        {
+          case 1:
+            frame_size = (frame_size * 12000) / sample_rate;
+            frame_size = (frame_size + padding) * 4;
+            break;
+
+          case 2:
+            frame_size = (frame_size * 144000) / sample_rate;
+            frame_size += padding;
+            break;
+
+          default:
+          case 3:
+            frame_size = (frame_size * 144000) / (sample_rate << lsf);
+            frame_size += padding;
+            break;
+        }
+    }
+  else
+    {
+      /* if no frame size computed, signal it */
+
+      return -EINVAL;
+    }
+
+  if (samplerate)
+    {
+      *samplerate = sample_rate;
+    }
+
+  if (chans)
+    {
+      *chans = mode == 3 ? 1 : 2;
+    }
+
+  if (bps)
+    {
+      *bps = 16;
+    }
+
+  return frame_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxplayer_parse_mp3
+ *
+ *   nxplayer_parse_mp3() parse mp3 header, get samplerate, channels, bps.
+ *
+ ****************************************************************************/
+
+int nxplayer_parse_mp3(int fd, FAR uint32_t *samplerate,
+                       FAR uint8_t *chans, FAR uint8_t *bps)
+{
+  uint32_t mpa_header;
+  uint8_t buffer[10];
+  off_t position;
+  int ret;
+
+  if (fd == -1)
+    {
+      return -EINVAL;
+    }
+
+  read(fd, buffer, sizeof(buffer));
+  position = (buffer[6] & ID3V2_BIT_MASK) * 0x200000 +
+             (buffer[7] & ID3V2_BIT_MASK) * 0x4000 +
+             (buffer[8] & ID3V2_BIT_MASK) * 0x80 +
+             (buffer[9] & ID3V2_BIT_MASK) +
+             sizeof(buffer);
+
+  lseek(fd, position, SEEK_SET);
+
+  read(fd, buffer, 4);
+  mpa_header = buffer[0] << 24 |
+               buffer[1] << 16 |
+               buffer[2] << 8  |
+               buffer[3];
+
+  ret = nxplayer_parse_mpeg(mpa_header, samplerate, chans, bps);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  lseek(fd, position, SEEK_SET);
+  return OK;
+}
+
+/****************************************************************************
+ * Name: nxplayer_fill_mp3
+ *
+ *   nxplayer_fill_mp3 fill mp3 data into apb buffer.
+ *
+ ****************************************************************************/
+
+int nxplayer_fill_mp3(int fd, FAR struct ap_buffer_s *apb)
+{
+  uint32_t mpa_header;
+  uint8_t header[16];
+  int h_size;
+  int b_size;
+  off_t pos;
+  int size;
+  int ret;
+
+  if (fd == -1)
+    {
+      return -EINVAL;
+    }
+
+  h_size = 4;
+  ret = read(fd, header, h_size);
+  if (ret < h_size)
+    {
+      return -ENODATA;
+    }
+
+  mpa_header = header[0] << 24 |
+               header[1] << 16 |
+               header[2] << 8  |
+               header[3];
+
+  size = nxplayer_parse_mpeg(mpa_header, NULL, NULL, NULL);
+  if (size < 0)
+    {
+      return size;
+    }
+
+  memcpy(apb->samp, header, h_size);
+
+  b_size = size - h_size;
+  ret = read(fd, apb->samp + h_size, b_size + 8);
+  if (ret < b_size)
+    {
+      return -ENODATA;
+    }
+
+  pos = lseek(fd, 0, SEEK_CUR);
+  lseek(fd, pos - 8, SEEK_SET);

Review Comment:
   ```suggestion
     lseek(fd,  -8, SEEK_CUR);
   ```
   and remove line 313



##########
system/nxplayer/nxplayer_mp3.c:
##########
@@ -0,0 +1,321 @@
+/****************************************************************************
+ * apps/system/nxplayer/nxplayer_mp3.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <nuttx/audio/audio.h>
+
+#include "system/nxplayer.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ID3V2_BIT_MASK 0x7F
+
+/****************************************************************************
+ * Private Type Declarations
+ ****************************************************************************/
+
+const static uint16_t g_mpa_freq_tab[3] =
+{
+  44100, 48000, 32000
+};
+
+const static uint16_t g_mpa_bitrate_tab[2][3][15] =
+{
+  {
+    {
+      0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448
+    },
+    {
+      0, 32, 48, 56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320, 384
+    },
+    {
+      0, 32, 40, 48,  56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320
+    }
+  },
+  {
+    {
+      0, 32, 48, 56,  64,  80,  96, 112, 128, 144, 160, 176, 192, 224, 256
+    },
+    {
+      0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160
+    },
+    {
+      0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160
+    }
+  }
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int nxplayer_check_mpeg(uint32_t header)
+{
+  int ret = -EINVAL;
+
+  /* header */
+
+  if ((header & 0xffe00000) != 0xffe00000)
+    {
+      return ret;
+    }
+
+  /* version check */
+
+  if ((header & (3 << 19)) == 1 << 19)
+    {
+      return ret;
+    }
+
+  /* layer check */
+
+  if ((header & (3 << 17)) == 0)
+    {
+      return ret;
+    }
+
+  /* bit rate */
+
+  if ((header & (0xf << 12)) == 0xf << 12)
+    {
+      return ret;
+    }
+
+  /* frequency */
+
+  if ((header & (3 << 10)) == 3 << 10)
+    {
+      return ret;
+    }
+
+  return 0;
+}
+
+static int nxplayer_parse_mpeg(uint32_t header, FAR uint32_t *samplerate,
+                               FAR uint8_t *chans, FAR uint8_t *bps)
+{
+  int sample_rate;
+  int frame_size;
+  int padding;
+  int mpeg25;
+  int sr_idx;
+  int br_idx;
+  int layer;
+  int mode;
+  int lsf;
+  int ret;
+
+  ret = nxplayer_check_mpeg(header);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  if (header & (1 << 20))
+    {
+      lsf = (header & (1 << 19)) ? 0 : 1;
+      mpeg25 = 0;
+    }
+  else
+    {
+      lsf = 1;
+      mpeg25 = 1;
+    }
+
+  layer   = 4 - ((header >> 17) & 3);
+  br_idx  = (header >> 12) & 0xf;
+  sr_idx  = (header >> 10) & 3;
+  padding = (header >> 9) & 1;
+  mode    = (header >> 6) & 3;
+
+  if (sr_idx >= sizeof(g_mpa_freq_tab) / sizeof(g_mpa_freq_tab[0]) ||
+      br_idx >= 0xf)
+    {
+      return -EINVAL;
+    }
+
+  sample_rate = g_mpa_freq_tab[sr_idx] >> (lsf + mpeg25);
+
+  if (br_idx != 0)
+    {
+      frame_size = g_mpa_bitrate_tab[lsf][layer - 1][br_idx];
+
+      switch (layer)
+        {
+          case 1:
+            frame_size = (frame_size * 12000) / sample_rate;
+            frame_size = (frame_size + padding) * 4;
+            break;
+
+          case 2:
+            frame_size = (frame_size * 144000) / sample_rate;
+            frame_size += padding;
+            break;
+
+          default:
+          case 3:
+            frame_size = (frame_size * 144000) / (sample_rate << lsf);
+            frame_size += padding;
+            break;
+        }
+    }
+  else
+    {
+      /* if no frame size computed, signal it */
+
+      return -EINVAL;
+    }
+
+  if (samplerate)
+    {
+      *samplerate = sample_rate;
+    }
+
+  if (chans)
+    {
+      *chans = mode == 3 ? 1 : 2;
+    }
+
+  if (bps)
+    {
+      *bps = 16;
+    }
+
+  return frame_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxplayer_parse_mp3
+ *
+ *   nxplayer_parse_mp3() parse mp3 header, get samplerate, channels, bps.
+ *
+ ****************************************************************************/
+
+int nxplayer_parse_mp3(int fd, FAR uint32_t *samplerate,
+                       FAR uint8_t *chans, FAR uint8_t *bps)
+{
+  uint32_t mpa_header;
+  uint8_t buffer[10];
+  off_t position;
+  int ret;
+
+  if (fd == -1)
+    {
+      return -EINVAL;
+    }
+
+  read(fd, buffer, sizeof(buffer));

Review Comment:
   ```suggestion
     ret = read(fd, buffer, sizeof(buffer));
     if (ret < sizeof(buffer))
       {
         return -ENODATA;
       }
   ```



##########
system/nxplayer/nxplayer_mp3.c:
##########
@@ -0,0 +1,321 @@
+/****************************************************************************
+ * apps/system/nxplayer/nxplayer_mp3.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <nuttx/audio/audio.h>
+
+#include "system/nxplayer.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ID3V2_BIT_MASK 0x7F
+
+/****************************************************************************
+ * Private Type Declarations
+ ****************************************************************************/
+
+const static uint16_t g_mpa_freq_tab[3] =
+{
+  44100, 48000, 32000
+};
+
+const static uint16_t g_mpa_bitrate_tab[2][3][15] =
+{
+  {
+    {
+      0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448
+    },
+    {
+      0, 32, 48, 56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320, 384
+    },
+    {
+      0, 32, 40, 48,  56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320
+    }
+  },
+  {
+    {
+      0, 32, 48, 56,  64,  80,  96, 112, 128, 144, 160, 176, 192, 224, 256
+    },
+    {
+      0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160
+    },
+    {
+      0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160
+    }
+  }
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int nxplayer_check_mpeg(uint32_t header)
+{
+  int ret = -EINVAL;
+
+  /* header */
+
+  if ((header & 0xffe00000) != 0xffe00000)
+    {
+      return ret;
+    }
+
+  /* version check */
+
+  if ((header & (3 << 19)) == 1 << 19)
+    {
+      return ret;
+    }
+
+  /* layer check */
+
+  if ((header & (3 << 17)) == 0)
+    {
+      return ret;
+    }
+
+  /* bit rate */
+
+  if ((header & (0xf << 12)) == 0xf << 12)
+    {
+      return ret;
+    }
+
+  /* frequency */
+
+  if ((header & (3 << 10)) == 3 << 10)
+    {
+      return ret;
+    }
+
+  return 0;
+}
+
+static int nxplayer_parse_mpeg(uint32_t header, FAR uint32_t *samplerate,
+                               FAR uint8_t *chans, FAR uint8_t *bps)
+{
+  int sample_rate;
+  int frame_size;
+  int padding;
+  int mpeg25;
+  int sr_idx;
+  int br_idx;
+  int layer;
+  int mode;
+  int lsf;
+  int ret;
+
+  ret = nxplayer_check_mpeg(header);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  if (header & (1 << 20))
+    {
+      lsf = (header & (1 << 19)) ? 0 : 1;
+      mpeg25 = 0;
+    }
+  else
+    {
+      lsf = 1;
+      mpeg25 = 1;
+    }
+
+  layer   = 4 - ((header >> 17) & 3);
+  br_idx  = (header >> 12) & 0xf;
+  sr_idx  = (header >> 10) & 3;
+  padding = (header >> 9) & 1;
+  mode    = (header >> 6) & 3;
+
+  if (sr_idx >= sizeof(g_mpa_freq_tab) / sizeof(g_mpa_freq_tab[0]) ||
+      br_idx >= 0xf)
+    {
+      return -EINVAL;
+    }
+
+  sample_rate = g_mpa_freq_tab[sr_idx] >> (lsf + mpeg25);
+
+  if (br_idx != 0)
+    {
+      frame_size = g_mpa_bitrate_tab[lsf][layer - 1][br_idx];
+
+      switch (layer)
+        {
+          case 1:
+            frame_size = (frame_size * 12000) / sample_rate;
+            frame_size = (frame_size + padding) * 4;
+            break;
+
+          case 2:
+            frame_size = (frame_size * 144000) / sample_rate;
+            frame_size += padding;
+            break;
+
+          default:
+          case 3:
+            frame_size = (frame_size * 144000) / (sample_rate << lsf);
+            frame_size += padding;
+            break;
+        }
+    }
+  else
+    {
+      /* if no frame size computed, signal it */
+
+      return -EINVAL;
+    }
+
+  if (samplerate)
+    {
+      *samplerate = sample_rate;
+    }
+
+  if (chans)
+    {
+      *chans = mode == 3 ? 1 : 2;
+    }
+
+  if (bps)
+    {
+      *bps = 16;
+    }
+
+  return frame_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxplayer_parse_mp3
+ *
+ *   nxplayer_parse_mp3() parse mp3 header, get samplerate, channels, bps.
+ *
+ ****************************************************************************/
+
+int nxplayer_parse_mp3(int fd, FAR uint32_t *samplerate,
+                       FAR uint8_t *chans, FAR uint8_t *bps)
+{
+  uint32_t mpa_header;
+  uint8_t buffer[10];
+  off_t position;
+  int ret;
+
+  if (fd == -1)

Review Comment:
   remove the check



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx-apps] qiaohaijiao commented on a diff in pull request #1440: nxplayer: add mp3 offload playback demo

Posted by GitBox <gi...@apache.org>.
qiaohaijiao commented on code in PR #1440:
URL: https://github.com/apache/nuttx-apps/pull/1440#discussion_r1037809858


##########
system/nxplayer/nxplayer_mp3.c:
##########
@@ -0,0 +1,321 @@
+/****************************************************************************
+ * apps/system/nxplayer/nxplayer_mp3.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <nuttx/audio/audio.h>
+
+#include "system/nxplayer.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ID3V2_BIT_MASK 0x7F
+
+/****************************************************************************
+ * Private Type Declarations
+ ****************************************************************************/
+
+const static uint16_t g_mpa_freq_tab[3] =
+{
+  44100, 48000, 32000
+};
+
+const static uint16_t g_mpa_bitrate_tab[2][3][15] =
+{
+  {
+    {
+      0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448
+    },
+    {
+      0, 32, 48, 56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320, 384
+    },
+    {
+      0, 32, 40, 48,  56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320
+    }
+  },
+  {
+    {
+      0, 32, 48, 56,  64,  80,  96, 112, 128, 144, 160, 176, 192, 224, 256
+    },
+    {
+      0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160
+    },
+    {
+      0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160
+    }
+  }
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int nxplayer_check_mpeg(uint32_t header)
+{
+  int ret = -EINVAL;
+
+  /* header */
+
+  if ((header & 0xffe00000) != 0xffe00000)
+    {
+      return ret;
+    }
+
+  /* version check */
+
+  if ((header & (3 << 19)) == 1 << 19)
+    {
+      return ret;
+    }
+
+  /* layer check */
+
+  if ((header & (3 << 17)) == 0)
+    {
+      return ret;
+    }
+
+  /* bit rate */
+
+  if ((header & (0xf << 12)) == 0xf << 12)
+    {
+      return ret;
+    }
+
+  /* frequency */
+
+  if ((header & (3 << 10)) == 3 << 10)
+    {
+      return ret;
+    }
+
+  return 0;
+}
+
+static int nxplayer_parse_mpeg(uint32_t header, FAR uint32_t *samplerate,
+                               FAR uint8_t *chans, FAR uint8_t *bps)
+{
+  int sample_rate;
+  int frame_size;
+  int padding;
+  int mpeg25;
+  int sr_idx;
+  int br_idx;
+  int layer;
+  int mode;
+  int lsf;
+  int ret;
+
+  ret = nxplayer_check_mpeg(header);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  if (header & (1 << 20))
+    {
+      lsf = (header & (1 << 19)) ? 0 : 1;
+      mpeg25 = 0;
+    }
+  else
+    {
+      lsf = 1;
+      mpeg25 = 1;
+    }
+
+  layer   = 4 - ((header >> 17) & 3);
+  br_idx  = (header >> 12) & 0xf;
+  sr_idx  = (header >> 10) & 3;
+  padding = (header >> 9) & 1;
+  mode    = (header >> 6) & 3;
+
+  if (sr_idx >= sizeof(g_mpa_freq_tab) / sizeof(g_mpa_freq_tab[0]) ||
+      br_idx >= 0xf)
+    {
+      return -EINVAL;
+    }
+
+  sample_rate = g_mpa_freq_tab[sr_idx] >> (lsf + mpeg25);
+
+  if (br_idx != 0)
+    {
+      frame_size = g_mpa_bitrate_tab[lsf][layer - 1][br_idx];
+
+      switch (layer)
+        {
+          case 1:
+            frame_size = (frame_size * 12000) / sample_rate;
+            frame_size = (frame_size + padding) * 4;
+            break;
+
+          case 2:
+            frame_size = (frame_size * 144000) / sample_rate;
+            frame_size += padding;
+            break;
+
+          default:
+          case 3:
+            frame_size = (frame_size * 144000) / (sample_rate << lsf);
+            frame_size += padding;
+            break;
+        }
+    }
+  else
+    {
+      /* if no frame size computed, signal it */
+
+      return -EINVAL;
+    }
+
+  if (samplerate)
+    {
+      *samplerate = sample_rate;
+    }
+
+  if (chans)
+    {
+      *chans = mode == 3 ? 1 : 2;
+    }
+
+  if (bps)
+    {
+      *bps = 16;
+    }
+
+  return frame_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxplayer_parse_mp3
+ *
+ *   nxplayer_parse_mp3() parse mp3 header, get samplerate, channels, bps.
+ *
+ ****************************************************************************/
+
+int nxplayer_parse_mp3(int fd, FAR uint32_t *samplerate,
+                       FAR uint8_t *chans, FAR uint8_t *bps)
+{
+  uint32_t mpa_header;
+  uint8_t buffer[10];
+  off_t position;
+  int ret;
+
+  if (fd == -1)
+    {
+      return -EINVAL;
+    }
+
+  read(fd, buffer, sizeof(buffer));

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx-apps] pkarashchenko commented on a diff in pull request #1440: nxplayer: add mp3 offload playback demo

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #1440:
URL: https://github.com/apache/nuttx-apps/pull/1440#discussion_r1037706680


##########
include/system/nxplayer.h:
##########
@@ -39,6 +39,14 @@
  * Public Type Declarations
  ****************************************************************************/
 
+struct nxplayer_dec_ops_s
+{
+  int format;
+  CODE int (*pre_parse)(int fd, uint32_t *samplerate,
+                   uint8_t *chans, uint8_t *bps);

Review Comment:
   ```suggestion
     CODE int (*pre_parse)(int fd, FAR uint32_t *samplerate,
   -                       FAR uint8_t *chans, FAR uint8_t *bps);
   
   ```



##########
include/system/nxplayer.h:
##########
@@ -72,6 +80,8 @@ struct nxplayer_s
   uint16_t    treble;         /* Treble as a whole % */
   uint16_t    bass;           /* Bass as a whole % */
 #endif
+
+  const struct nxplayer_dec_ops_s *ops;

Review Comment:
   ```suggestion
     FAR const struct nxplayer_dec_ops_s *ops;
   ```



##########
system/nxplayer/nxplayer.c:
##########
@@ -121,6 +131,27 @@ static const struct nxplayer_ext_fmt_s g_known_ext[] =
 
 static const int g_known_ext_count = sizeof(g_known_ext) /
                     sizeof(struct nxplayer_ext_fmt_s);
+
+static const struct nxplayer_dec_ops_s g_dec_mp3 =
+{
+  AUDIO_FMT_MP3,
+  nxplayer_parse_mp3,
+  nxplayer_fill_mp3
+};
+
+static const struct nxplayer_dec_ops_s g_dec_pcm =
+{
+  AUDIO_FMT_PCM,
+  NULL,
+  nxplayer_fill_pcm
+};
+
+static const struct nxplayer_dec_ops_s g_dec_s[] =

Review Comment:
   can we use reference to `g_dec_pcm` and `g_dec_mp3` instead of copy?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx-apps] xiaoxiang781216 commented on a diff in pull request #1440: nxplayer: add mp3 offload playback demo

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #1440:
URL: https://github.com/apache/nuttx-apps/pull/1440#discussion_r1037883978


##########
system/nxplayer/nxplayer.c:
##########
@@ -80,6 +80,12 @@ struct nxplayer_ext_fmt_s
 };
 #endif
 
+struct nxplayer_fmt_s

Review Comment:
   remove, no user



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx-apps] qiaohaijiao commented on a diff in pull request #1440: nxplayer: add mp3 offload playback demo

Posted by GitBox <gi...@apache.org>.
qiaohaijiao commented on code in PR #1440:
URL: https://github.com/apache/nuttx-apps/pull/1440#discussion_r1037819055


##########
include/system/nxplayer.h:
##########
@@ -72,6 +80,8 @@ struct nxplayer_s
   uint16_t    treble;         /* Treble as a whole % */
   uint16_t    bass;           /* Bass as a whole % */
 #endif
+
+  const struct nxplayer_dec_ops_s *ops;

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx-apps] qiaohaijiao commented on a diff in pull request #1440: nxplayer: add mp3 offload playback demo

Posted by GitBox <gi...@apache.org>.
qiaohaijiao commented on code in PR #1440:
URL: https://github.com/apache/nuttx-apps/pull/1440#discussion_r1038011536


##########
system/nxplayer/nxplayer.c:
##########
@@ -121,6 +131,27 @@ static const struct nxplayer_ext_fmt_s g_known_ext[] =
 
 static const int g_known_ext_count = sizeof(g_known_ext) /
                     sizeof(struct nxplayer_ext_fmt_s);
+
+static const struct nxplayer_dec_ops_s g_dec_mp3 =
+{
+  AUDIO_FMT_MP3,
+  nxplayer_parse_mp3,
+  nxplayer_fill_mp3
+};
+
+static const struct nxplayer_dec_ops_s g_dec_pcm =
+{
+  AUDIO_FMT_PCM,
+  NULL,
+  nxplayer_fill_pcm
+};
+
+static const struct nxplayer_dec_ops_s g_dec_s[] =

Review Comment:
   hi pkarashchenko, 
   i've got what you said, and fixed.   
   thanks.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx-apps] qiaohaijiao commented on a diff in pull request #1440: nxplayer: add mp3 offload playback demo

Posted by GitBox <gi...@apache.org>.
qiaohaijiao commented on code in PR #1440:
URL: https://github.com/apache/nuttx-apps/pull/1440#discussion_r1035584373


##########
include/system/nxplayer.h:
##########
@@ -39,6 +39,14 @@
  * Public Type Declarations
  ****************************************************************************/
 
+struct nxplayer_dec_ops_s
+{
+  int format;
+  int (*pre_parse)(int fd, uint32_t *samplerate,
+                   uint8_t *chans, uint8_t *bps);

Review Comment:
   done



##########
include/system/nxplayer.h:
##########
@@ -39,6 +39,14 @@
  * Public Type Declarations
  ****************************************************************************/
 
+struct nxplayer_dec_ops_s
+{
+  int format;
+  int (*pre_parse)(int fd, uint32_t *samplerate,
+                   uint8_t *chans, uint8_t *bps);
+  int (*fill_data)(int fd, FAR struct ap_buffer_s *apb);

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx-apps] qiaohaijiao commented on a diff in pull request #1440: nxplayer: add mp3 offload playback demo

Posted by GitBox <gi...@apache.org>.
qiaohaijiao commented on code in PR #1440:
URL: https://github.com/apache/nuttx-apps/pull/1440#discussion_r1037793787


##########
system/nxplayer/nxplayer_mp3.c:
##########
@@ -0,0 +1,321 @@
+/****************************************************************************
+ * apps/system/nxplayer/nxplayer_mp3.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <nuttx/audio/audio.h>
+
+#include "system/nxplayer.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ID3V2_BIT_MASK 0x7F
+
+/****************************************************************************
+ * Private Type Declarations
+ ****************************************************************************/
+
+const static uint16_t g_mpa_freq_tab[3] =
+{
+  44100, 48000, 32000
+};
+
+const static uint16_t g_mpa_bitrate_tab[2][3][15] =
+{
+  {
+    {
+      0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448
+    },
+    {
+      0, 32, 48, 56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320, 384
+    },
+    {
+      0, 32, 40, 48,  56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320
+    }
+  },
+  {
+    {
+      0, 32, 48, 56,  64,  80,  96, 112, 128, 144, 160, 176, 192, 224, 256
+    },
+    {
+      0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160
+    },
+    {
+      0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160
+    }
+  }
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int nxplayer_check_mpeg(uint32_t header)
+{
+  int ret = -EINVAL;
+
+  /* header */
+
+  if ((header & 0xffe00000) != 0xffe00000)
+    {
+      return ret;
+    }
+
+  /* version check */
+
+  if ((header & (3 << 19)) == 1 << 19)
+    {
+      return ret;
+    }
+
+  /* layer check */
+
+  if ((header & (3 << 17)) == 0)
+    {
+      return ret;
+    }
+
+  /* bit rate */
+
+  if ((header & (0xf << 12)) == 0xf << 12)
+    {
+      return ret;
+    }
+
+  /* frequency */
+
+  if ((header & (3 << 10)) == 3 << 10)
+    {
+      return ret;
+    }
+
+  return 0;
+}
+
+static int nxplayer_parse_mpeg(uint32_t header, FAR uint32_t *samplerate,
+                               FAR uint8_t *chans, FAR uint8_t *bps)
+{
+  int sample_rate;
+  int frame_size;
+  int padding;
+  int mpeg25;
+  int sr_idx;
+  int br_idx;
+  int layer;
+  int mode;
+  int lsf;
+  int ret;
+
+  ret = nxplayer_check_mpeg(header);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  if (header & (1 << 20))
+    {
+      lsf = (header & (1 << 19)) ? 0 : 1;
+      mpeg25 = 0;
+    }
+  else
+    {
+      lsf = 1;
+      mpeg25 = 1;
+    }
+
+  layer   = 4 - ((header >> 17) & 3);
+  br_idx  = (header >> 12) & 0xf;
+  sr_idx  = (header >> 10) & 3;
+  padding = (header >> 9) & 1;
+  mode    = (header >> 6) & 3;
+
+  if (sr_idx >= sizeof(g_mpa_freq_tab) / sizeof(g_mpa_freq_tab[0]) ||
+      br_idx >= 0xf)
+    {
+      return -EINVAL;
+    }
+
+  sample_rate = g_mpa_freq_tab[sr_idx] >> (lsf + mpeg25);
+
+  if (br_idx != 0)
+    {
+      frame_size = g_mpa_bitrate_tab[lsf][layer - 1][br_idx];
+
+      switch (layer)
+        {
+          case 1:
+            frame_size = (frame_size * 12000) / sample_rate;
+            frame_size = (frame_size + padding) * 4;
+            break;
+
+          case 2:
+            frame_size = (frame_size * 144000) / sample_rate;
+            frame_size += padding;
+            break;
+
+          default:
+          case 3:
+            frame_size = (frame_size * 144000) / (sample_rate << lsf);
+            frame_size += padding;
+            break;
+        }
+    }
+  else
+    {
+      /* if no frame size computed, signal it */
+
+      return -EINVAL;
+    }
+
+  if (samplerate)
+    {
+      *samplerate = sample_rate;
+    }
+
+  if (chans)
+    {
+      *chans = mode == 3 ? 1 : 2;
+    }
+
+  if (bps)
+    {
+      *bps = 16;
+    }
+
+  return frame_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxplayer_parse_mp3
+ *
+ *   nxplayer_parse_mp3() parse mp3 header, get samplerate, channels, bps.
+ *
+ ****************************************************************************/
+
+int nxplayer_parse_mp3(int fd, FAR uint32_t *samplerate,
+                       FAR uint8_t *chans, FAR uint8_t *bps)
+{
+  uint32_t mpa_header;
+  uint8_t buffer[10];
+  off_t position;
+  int ret;
+
+  if (fd == -1)
+    {
+      return -EINVAL;
+    }
+
+  read(fd, buffer, sizeof(buffer));
+  position = (buffer[6] & ID3V2_BIT_MASK) * 0x200000 +
+             (buffer[7] & ID3V2_BIT_MASK) * 0x4000 +
+             (buffer[8] & ID3V2_BIT_MASK) * 0x80 +
+             (buffer[9] & ID3V2_BIT_MASK) +
+             sizeof(buffer);
+
+  lseek(fd, position, SEEK_SET);
+
+  read(fd, buffer, 4);
+  mpa_header = buffer[0] << 24 |
+               buffer[1] << 16 |
+               buffer[2] << 8  |
+               buffer[3];
+
+  ret = nxplayer_parse_mpeg(mpa_header, samplerate, chans, bps);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  lseek(fd, position, SEEK_SET);
+  return OK;
+}
+
+/****************************************************************************
+ * Name: nxplayer_fill_mp3
+ *
+ *   nxplayer_fill_mp3 fill mp3 data into apb buffer.
+ *
+ ****************************************************************************/
+
+int nxplayer_fill_mp3(int fd, FAR struct ap_buffer_s *apb)
+{
+  uint32_t mpa_header;
+  uint8_t header[16];
+  int h_size;
+  int b_size;
+  off_t pos;
+  int size;
+  int ret;
+
+  if (fd == -1)
+    {
+      return -EINVAL;
+    }
+
+  h_size = 4;
+  ret = read(fd, header, h_size);
+  if (ret < h_size)
+    {
+      return -ENODATA;
+    }
+
+  mpa_header = header[0] << 24 |
+               header[1] << 16 |
+               header[2] << 8  |
+               header[3];
+
+  size = nxplayer_parse_mpeg(mpa_header, NULL, NULL, NULL);
+  if (size < 0)
+    {
+      return size;
+    }
+
+  memcpy(apb->samp, header, h_size);
+
+  b_size = size - h_size;
+  ret = read(fd, apb->samp + h_size, b_size + 8);
+  if (ret < b_size)
+    {
+      return -ENODATA;
+    }
+
+  pos = lseek(fd, 0, SEEK_CUR);
+  lseek(fd, pos - 8, SEEK_SET);

Review Comment:
   done



##########
system/nxplayer/nxplayer_mp3.c:
##########
@@ -0,0 +1,321 @@
+/****************************************************************************
+ * apps/system/nxplayer/nxplayer_mp3.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <nuttx/audio/audio.h>
+
+#include "system/nxplayer.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ID3V2_BIT_MASK 0x7F
+
+/****************************************************************************
+ * Private Type Declarations
+ ****************************************************************************/
+
+const static uint16_t g_mpa_freq_tab[3] =
+{
+  44100, 48000, 32000
+};
+
+const static uint16_t g_mpa_bitrate_tab[2][3][15] =
+{
+  {
+    {
+      0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448
+    },
+    {
+      0, 32, 48, 56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320, 384
+    },
+    {
+      0, 32, 40, 48,  56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320
+    }
+  },
+  {
+    {
+      0, 32, 48, 56,  64,  80,  96, 112, 128, 144, 160, 176, 192, 224, 256
+    },
+    {
+      0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160
+    },
+    {
+      0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160
+    }
+  }
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int nxplayer_check_mpeg(uint32_t header)
+{
+  int ret = -EINVAL;
+
+  /* header */
+
+  if ((header & 0xffe00000) != 0xffe00000)
+    {
+      return ret;
+    }
+
+  /* version check */
+
+  if ((header & (3 << 19)) == 1 << 19)
+    {
+      return ret;
+    }
+
+  /* layer check */
+
+  if ((header & (3 << 17)) == 0)
+    {
+      return ret;
+    }
+
+  /* bit rate */
+
+  if ((header & (0xf << 12)) == 0xf << 12)
+    {
+      return ret;
+    }
+
+  /* frequency */
+
+  if ((header & (3 << 10)) == 3 << 10)
+    {
+      return ret;
+    }
+
+  return 0;
+}
+
+static int nxplayer_parse_mpeg(uint32_t header, FAR uint32_t *samplerate,
+                               FAR uint8_t *chans, FAR uint8_t *bps)
+{
+  int sample_rate;
+  int frame_size;
+  int padding;
+  int mpeg25;
+  int sr_idx;
+  int br_idx;
+  int layer;
+  int mode;
+  int lsf;
+  int ret;
+
+  ret = nxplayer_check_mpeg(header);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  if (header & (1 << 20))
+    {
+      lsf = (header & (1 << 19)) ? 0 : 1;
+      mpeg25 = 0;
+    }
+  else
+    {
+      lsf = 1;
+      mpeg25 = 1;
+    }
+
+  layer   = 4 - ((header >> 17) & 3);
+  br_idx  = (header >> 12) & 0xf;
+  sr_idx  = (header >> 10) & 3;
+  padding = (header >> 9) & 1;
+  mode    = (header >> 6) & 3;
+
+  if (sr_idx >= sizeof(g_mpa_freq_tab) / sizeof(g_mpa_freq_tab[0]) ||
+      br_idx >= 0xf)
+    {
+      return -EINVAL;
+    }
+
+  sample_rate = g_mpa_freq_tab[sr_idx] >> (lsf + mpeg25);
+
+  if (br_idx != 0)
+    {
+      frame_size = g_mpa_bitrate_tab[lsf][layer - 1][br_idx];
+
+      switch (layer)
+        {
+          case 1:
+            frame_size = (frame_size * 12000) / sample_rate;
+            frame_size = (frame_size + padding) * 4;
+            break;
+
+          case 2:
+            frame_size = (frame_size * 144000) / sample_rate;
+            frame_size += padding;
+            break;
+
+          default:
+          case 3:
+            frame_size = (frame_size * 144000) / (sample_rate << lsf);
+            frame_size += padding;
+            break;
+        }
+    }
+  else
+    {
+      /* if no frame size computed, signal it */
+
+      return -EINVAL;
+    }
+
+  if (samplerate)
+    {
+      *samplerate = sample_rate;
+    }
+
+  if (chans)
+    {
+      *chans = mode == 3 ? 1 : 2;
+    }
+
+  if (bps)
+    {
+      *bps = 16;
+    }
+
+  return frame_size;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxplayer_parse_mp3
+ *
+ *   nxplayer_parse_mp3() parse mp3 header, get samplerate, channels, bps.
+ *
+ ****************************************************************************/
+
+int nxplayer_parse_mp3(int fd, FAR uint32_t *samplerate,
+                       FAR uint8_t *chans, FAR uint8_t *bps)
+{
+  uint32_t mpa_header;
+  uint8_t buffer[10];
+  off_t position;
+  int ret;
+
+  if (fd == -1)

Review Comment:
   done



##########
system/nxplayer/nxplayer_mp3.c:
##########
@@ -0,0 +1,321 @@
+/****************************************************************************
+ * apps/system/nxplayer/nxplayer_mp3.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/types.h>
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <nuttx/audio/audio.h>
+
+#include "system/nxplayer.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ID3V2_BIT_MASK 0x7F
+
+/****************************************************************************
+ * Private Type Declarations
+ ****************************************************************************/
+
+const static uint16_t g_mpa_freq_tab[3] =
+{
+  44100, 48000, 32000
+};
+
+const static uint16_t g_mpa_bitrate_tab[2][3][15] =
+{
+  {
+    {
+      0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448
+    },
+    {
+      0, 32, 48, 56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320, 384
+    },
+    {
+      0, 32, 40, 48,  56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320
+    }
+  },
+  {
+    {
+      0, 32, 48, 56,  64,  80,  96, 112, 128, 144, 160, 176, 192, 224, 256
+    },
+    {
+      0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160
+    },
+    {
+      0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160
+    }
+  }
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int nxplayer_check_mpeg(uint32_t header)
+{
+  int ret = -EINVAL;
+
+  /* header */
+
+  if ((header & 0xffe00000) != 0xffe00000)
+    {
+      return ret;

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx-apps] qiaohaijiao commented on a diff in pull request #1440: nxplayer: add mp3 offload playback demo

Posted by GitBox <gi...@apache.org>.
qiaohaijiao commented on code in PR #1440:
URL: https://github.com/apache/nuttx-apps/pull/1440#discussion_r1037818887


##########
include/system/nxplayer.h:
##########
@@ -39,6 +39,14 @@
  * Public Type Declarations
  ****************************************************************************/
 
+struct nxplayer_dec_ops_s
+{
+  int format;
+  CODE int (*pre_parse)(int fd, uint32_t *samplerate,
+                   uint8_t *chans, uint8_t *bps);

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx-apps] xiaoxiang781216 merged pull request #1440: nxplayer: add mp3 offload playback demo

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 merged PR #1440:
URL: https://github.com/apache/nuttx-apps/pull/1440


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx-apps] pkarashchenko commented on a diff in pull request #1440: nxplayer: add mp3 offload playback demo

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #1440:
URL: https://github.com/apache/nuttx-apps/pull/1440#discussion_r1037920760


##########
system/nxplayer/nxplayer.c:
##########
@@ -121,6 +131,27 @@ static const struct nxplayer_ext_fmt_s g_known_ext[] =
 
 static const int g_known_ext_count = sizeof(g_known_ext) /
                     sizeof(struct nxplayer_ext_fmt_s);
+
+static const struct nxplayer_dec_ops_s g_dec_mp3 =
+{
+  AUDIO_FMT_MP3,
+  nxplayer_parse_mp3,
+  nxplayer_fill_mp3
+};
+
+static const struct nxplayer_dec_ops_s g_dec_pcm =
+{
+  AUDIO_FMT_PCM,
+  NULL,
+  nxplayer_fill_pcm
+};
+
+static const struct nxplayer_dec_ops_s g_dec_s[] =

Review Comment:
   > hello pkarashchenko, 
   > there is no copy, use the reference of g_dec_pcm or g_dec_mp3 in function `nxplayer_playinternal`.
   > 
   > 
   
   But `g_dec_s` array contain the copy of those structs, isn't it?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org