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/29 04:33:37 UTC

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

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