[Android] question about code structure to make modifications to vlc to support asset loading

Kevin Whitaker kevin at lisnr.com
Mon Jan 4 21:43:05 CET 2016


I forgot something important in the past two diffs. I never had set the
values into the struct. Now I have video playing. This should be the final
diff unless there is something found wrong with it.

Index: modules/access/file.c
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- modules/access/file.c    (date 1449063148000)
+++ modules/access/file.c    (revision )
@@ -3,7 +3,7 @@

*****************************************************************************
  * Copyright (C) 2001-2006 VLC authors and VideoLAN
  * Copyright © 2006-2007 Rémi Denis-Courmont
- * $Id$
+ * $Id: 48482790da310350a109e62f0f2b64f90b09dc43 $
  *
  * Authors: Christophe Massiot <massiot at via.ecp.fr>
  *          Rémi Denis-Courmont <rem # videolan # org>
@@ -69,6 +69,10 @@
 {
     int fd;

+    long fd_offset;
+
+    long fd_size;
+
     bool b_pace_control;
 };

@@ -143,10 +147,67 @@
     /* Open file */
     int fd = -1;

-    if (!strcasecmp (p_access->psz_access, "fd"))
-    {
+    /* Part of file to use */
+    long fd_offset = -1;
+    long fd_size = -1;
+
+    if (!strcasecmp (p_access->psz_access, "fd")) {
         char *end;
-        int oldfd = strtol (p_access->psz_location, &end, 10);
+        int oldfd;
+        /* Check if location data has bars that represent partial file
access
+         * ex. fd://20|65477|4456677|
+         */
+        if (strstr(p_access->psz_location, "|") != NULL)
+        {
+            char *location, *working_split, *saveptr;
+            location = malloc(strlen(p_access->psz_location));
+            strcpy(location, p_access->psz_location);
+            working_split = strtok_r(location, "|", &saveptr);
+            if (working_split != NULL)
+            {
+                oldfd = strtol(working_split, &end, 10);
+                working_split = strtok_r(NULL,"|",&saveptr);
+                if (working_split != NULL) {
+                    fd_offset = strtol(working_split, &end, 10);
+                    working_split = strtok_r(NULL,"|", &saveptr);
+                    if (working_split != NULL)
+                    {
+                        fd_size = strtol(working_split, &end, 10);
+                    }
+                    else
+                    {
+                        msg_Err (p_access, "cannot open file %s (%s).
Invalid.",
+                                 p_access->psz_filepath ?
p_access->psz_filepath
+                                                        :
p_access->psz_location,
+                                 vlc_strerror_c(errno));
+                        dialog_Fatal (p_access, _("File reading failed"),
+                                      _("VLC could not open the file
\"%s\" (%s). Invalid."),
+                                      p_access->psz_filepath ?
p_access->psz_filepath
+                                                             :
p_access->psz_location,
+                                      vlc_strerror(errno));
+                        return VLC_EGENERIC;
+                    }
+                }
+                else
+                {
+                    msg_Err (p_access, "cannot open file %s (%s).
Invalid.",
+                             p_access->psz_filepath ?
p_access->psz_filepath
+                                                    :
p_access->psz_location,
+                             vlc_strerror_c(errno));
+                    dialog_Fatal (p_access, _("File reading failed"),
+                                  _("VLC could not open the file \"%s\"
(%s). Invalid."),
+                                  p_access->psz_filepath ?
p_access->psz_filepath
+                                                         :
p_access->psz_location,
+                                  vlc_strerror(errno));
+                    return VLC_EGENERIC;
+                }
+            }
+            free(location);
+        }
+        else
+        {
+            oldfd = strtol(p_access->psz_location, &end, 10);
+        }

         if (*end == '\0')
             fd = vlc_dup (oldfd);
@@ -220,6 +281,8 @@
     p_access->pf_control = FileControl;
     p_access->p_sys = p_sys;
     p_sys->fd = fd;
+    p_sys->fd_offset = fd_offset;
+    p_sys->fd_size = fd_size;

     if (S_ISREG (st.st_mode) || S_ISBLK (st.st_mode))
     {
@@ -278,6 +341,11 @@
     access_sys_t *p_sys = p_access->p_sys;
     int fd = p_sys->fd;

+    /* If this is the first read of a file with an offset, seek to that
offset. */
+    if (p_sys->fd_offset != -1 && lseek(fd, 0, SEEK_CUR) == (off_t)0) {
+        lseek(fd, p_sys->fd_offset, SEEK_SET);
+    }
+
     ssize_t val = vlc_read_i11e (fd, p_buffer, i_len);
     if (val < 0)
     {
@@ -306,6 +374,12 @@
 {
     p_access->info.b_eof = false;

+    /* If this file has an offset, add offset to any seek position given.
*/
+    if (p_access->p_sys->fd_offset != -1)
+    {
+        i_pos = i_pos + p_access->p_sys->fd_offset;
+    }
+
     if (lseek (p_access->p_sys->fd, i_pos, SEEK_SET) == (off_t)-1)
         return VLC_EGENERIC;
     return VLC_SUCCESS;
@@ -347,7 +421,14 @@

             if (fstat (p_sys->fd, &st) || !S_ISREG(st.st_mode))
                 return VLC_EGENERIC;
+            if (p_sys->fd_offset != -1)
+            {
+                *va_arg( args, uint64_t * ) = (off_t)p_sys->fd_size;
+            }
+            else
+            {
-            *va_arg( args, uint64_t * ) = st.st_size;
+                *va_arg( args, uint64_t * ) = st.st_size;
+            }
             break;
         }


On Mon, Jan 4, 2016 at 1:02 PM, Kevin Whitaker <kevin at lisnr.com> wrote:

> Here is an update that includes some fixes after trying to test out the
> code. Major changes are fixed naive attempts to do memory management and
> using "|" instead of "#" due to other code in vlc striping them out. Sadly,
> even after those fixes, it still doesn't seem to be playing yet.
>
> Index: modules/access/file.c
> IDEA additional info:
> Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
> <+>UTF-8
> ===================================================================
> --- modules/access/file.c    (date 1449063148000)
> +++ modules/access/file.c    (revision )
> @@ -3,7 +3,7 @@
>
> *****************************************************************************
>   * Copyright (C) 2001-2006 VLC authors and VideoLAN
>   * Copyright © 2006-2007 Rémi Denis-Courmont
> - * $Id$
> + * $Id: 48482790da310350a109e62f0f2b64f90b09dc43 $
>   *
>   * Authors: Christophe Massiot <massiot at via.ecp.fr>
>   *          Rémi Denis-Courmont <rem # videolan # org>
> @@ -69,6 +69,10 @@
>  {
>      int fd;
>
> +    long fd_offset;
> +
> +    long fd_size;
> +
>      bool b_pace_control;
>  };
>
> @@ -143,10 +147,67 @@
>      /* Open file */
>      int fd = -1;
>
> -    if (!strcasecmp (p_access->psz_access, "fd"))
> -    {
> +    /* Part of file to use */
> +    long fd_offset = -1;
> +    long fd_size = -1;
> +
> +    if (!strcasecmp (p_access->psz_access, "fd")) {
>          char *end;
> -        int oldfd = strtol (p_access->psz_location, &end, 10);
> +        int oldfd;
> +        /* Check if location data has bars that represent partial file
> access
> +         * ex. fd://20|65477|4456677|
> +         */
> +        if (strstr(p_access->psz_location, "|") != NULL)
> +        {
> +            char *location, *working_split, *saveptr;
> +            location = malloc(strlen(p_access->psz_location));
> +            strcpy(location, p_access->psz_location);
> +            working_split = strtok_r(location, "|", &saveptr);
> +            if (working_split != NULL)
> +            {
> +                oldfd = strtol(working_split, &end, 10);
> +                working_split = strtok_r(NULL,"|",&saveptr);
> +                if (working_split != NULL) {
> +                    fd_offset = strtol(working_split, &end, 10);
> +                    working_split = strtok_r(NULL,"|", &saveptr);
>
> +                    if (working_split != NULL)
> +                    {
> +                        fd_size = strtol(working_split, &end, 10);
> +                    }
> +                    else
> +                    {
> +                        msg_Err (p_access, "cannot open file %s (%s).
> Invalid.",
> +                                 p_access->psz_filepath ?
> p_access->psz_filepath
> +                                                        :
> p_access->psz_location,
> +                                 vlc_strerror_c(errno));
> +                        dialog_Fatal (p_access, _("File reading failed"),
> +                                      _("VLC could not open the file
> \"%s\" (%s). Invalid."),
> +                                      p_access->psz_filepath ?
> p_access->psz_filepath
> +                                                             :
> p_access->psz_location,
> +                                      vlc_strerror(errno));
> +                        return VLC_EGENERIC;
> +                    }
> +                }
> +                else
> +                {
> +                    msg_Err (p_access, "cannot open file %s (%s).
> Invalid.",
> +                             p_access->psz_filepath ?
> p_access->psz_filepath
> +                                                    :
> p_access->psz_location,
> +                             vlc_strerror_c(errno));
> +                    dialog_Fatal (p_access, _("File reading failed"),
> +                                  _("VLC could not open the file \"%s\"
> (%s). Invalid."),
> +                                  p_access->psz_filepath ?
> p_access->psz_filepath
> +                                                         :
> p_access->psz_location,
> +                                  vlc_strerror(errno));
> +                    return VLC_EGENERIC;
> +                }
> +            }
> +            free(location);
> +        }
> +        else
> +        {
> +            oldfd = strtol(p_access->psz_location, &end, 10);
> +        }
>
>          if (*end == '\0')
>              fd = vlc_dup (oldfd);
> @@ -278,6 +339,11 @@
>      access_sys_t *p_sys = p_access->p_sys;
>      int fd = p_sys->fd;
>
> +    /* If this is the first read of a file with an offset, seek to that
> offset. */
> +    if (p_sys->fd_offset != -1 && lseek(fd, 0, SEEK_CUR) == (off_t)0) {
> +        lseek(fd, p_sys->fd_offset, SEEK_SET);
> +    }
> +
>      ssize_t val = vlc_read_i11e (fd, p_buffer, i_len);
>      if (val < 0)
>      {
> @@ -306,6 +372,12 @@
>  {
>      p_access->info.b_eof = false;
>
> +    /* If this file has an offset, add offset to any seek position given.
> */
> +    if (p_access->p_sys->fd_offset != -1)
> +    {
> +        i_pos = i_pos + p_access->p_sys->fd_offset;
> +    }
> +
>      if (lseek (p_access->p_sys->fd, i_pos, SEEK_SET) == (off_t)-1)
>          return VLC_EGENERIC;
>      return VLC_SUCCESS;
> @@ -347,7 +419,14 @@
>
>              if (fstat (p_sys->fd, &st) || !S_ISREG(st.st_mode))
>                  return VLC_EGENERIC;
> +            if (p_sys->fd_offset != -1)
> +            {
> +                *va_arg( args, uint64_t * ) = (off_t)p_sys->fd_size;
> +            }
> +            else
> +            {
> -            *va_arg( args, uint64_t * ) = st.st_size;
> +                *va_arg( args, uint64_t * ) = st.st_size;
> +            }
>              break;
>          }
>
>
> On Mon, Jan 4, 2016 at 9:34 AM, Kevin Whitaker <kevin at lisnr.com> wrote:
>
>> Just noticed the attachment doesn't show up right in my last email.
>> Pasting into body.
>>
>> Index: modules/access/file.c
>> IDEA additional info:
>> Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
>> <+>UTF-8
>> ===================================================================
>> --- modules/access/file.c    (date 1449063148000)
>> +++ modules/access/file.c    (revision )
>> @@ -3,7 +3,7 @@
>>
>> *****************************************************************************
>>   * Copyright (C) 2001-2006 VLC authors and VideoLAN
>>   * Copyright © 2006-2007 Rémi Denis-Courmont
>> - * $Id$
>> + * $Id: 48482790da310350a109e62f0f2b64f90b09dc43 $
>>   *
>>   * Authors: Christophe Massiot <massiot at via.ecp.fr>
>>   *          Rémi Denis-Courmont <rem # videolan # org>
>> @@ -69,6 +69,10 @@
>>  {
>>      int fd;
>>
>> +    long fd_offset;
>> +
>> +    long fd_size;
>> +
>>      bool b_pace_control;
>>  };
>>
>> @@ -143,10 +147,68 @@
>>      /* Open file */
>>      int fd = -1;
>>
>> -    if (!strcasecmp (p_access->psz_access, "fd"))
>> -    {
>> +    /* Part of file to use */
>> +    long fd_offset = -1;
>> +    long fd_size = -1;
>> +
>> +    if (!strcasecmp (p_access->psz_access, "fd")) {
>>          char *end;
>> -        int oldfd = strtol (p_access->psz_location, &end, 10);
>> +        int oldfd;
>> +        /* Check if location data has hashes that represent partial file
>> access
>> +         * ex. fd://20#65477#4456677#
>> +         */
>> +        if (strstr(p_access->psz_location, "#") != NULL)
>> +        {
>> +            char *location, working_split, saveptr;
>> +            strcpy(location, p_access->psz_location);
>> +            working_split = strtok_r(location, "#", &saveptr);
>> +            if (working_split != NULL)
>> +            {
>> +                oldfd = strtol(working_split, &end, 10);
>> +                working_split = strtok_r(NULL,"#",&saveptr);
>> +                if (working_split != NULL) {
>> +                    fd_offset = strtol(working_split, &end, 10);
>> +                    working_split = strtok_r(NULL,"#", &saveptr);
>> +                    if (working_split != NULL)
>> +                    {
>> +                        fd_size = strtol(working_split, &end, 10);
>> +                    }
>> +                    else
>> +                    {
>> +                        msg_Err (p_access, "cannot open file %s (%s).
>> Invalid.",
>> +                                 p_access->psz_filepath ?
>> p_access->psz_filepath
>> +                                                        :
>> p_access->psz_location,
>> +                                 vlc_strerror_c(errno));
>> +                        dialog_Fatal (p_access, _("File reading failed"),
>> +                                      _("VLC could not open the file
>> \"%s\" (%s). Invalid."),
>> +                                      p_access->psz_filepath ?
>> p_access->psz_filepath
>> +                                                             :
>> p_access->psz_location,
>> +                                      vlc_strerror(errno));
>> +                        return VLC_EGENERIC;
>> +                    }
>> +                }
>> +                else
>> +                {
>> +                    msg_Err (p_access, "cannot open file %s (%s).
>> Invalid.",
>> +                             p_access->psz_filepath ?
>> p_access->psz_filepath
>> +                                                    :
>> p_access->psz_location,
>> +                             vlc_strerror_c(errno));
>> +                    dialog_Fatal (p_access, _("File reading failed"),
>> +                                  _("VLC could not open the file \"%s\"
>> (%s). Invalid."),
>> +                                  p_access->psz_filepath ?
>> p_access->psz_filepath
>> +                                                         :
>> p_access->psz_location,
>> +                                  vlc_strerror(errno));
>> +                    return VLC_EGENERIC;
>> +                }
>> +            }
>> +            free(working_split);
>> +            free(location);
>> +            free(saveptr);
>> +        }
>> +        else
>> +        {
>> +            oldfd = strtol(p_access->psz_location, &end, 10);
>> +        }
>>
>>          if (*end == '\0')
>>              fd = vlc_dup (oldfd);
>> @@ -278,6 +340,11 @@
>>      access_sys_t *p_sys = p_access->p_sys;
>>      int fd = p_sys->fd;
>>
>> +    /* If this is the first read of a file with an offset, seek to that
>> offset. */
>> +    if (p_sys->fd_offset != -1 && lseek(fd, 0, SEEK_CUR) == (off_t)0) {
>> +        lseek(fd, p_sys->fd_offset, SEEK_SET);
>> +    }
>> +
>>      ssize_t val = vlc_read_i11e (fd, p_buffer, i_len);
>>      if (val < 0)
>>      {
>> @@ -306,6 +373,12 @@
>>  {
>>      p_access->info.b_eof = false;
>>
>> +    /* If this file has an offset, add offset to any seek position
>> given. */
>> +    if (p_access->p_sys->fd_offset != -1)
>> +    {
>> +        i_pos = i_pos + p_access->p_sys->fd_offset;
>> +    }
>> +
>>      if (lseek (p_access->p_sys->fd, i_pos, SEEK_SET) == (off_t)-1)
>>          return VLC_EGENERIC;
>>      return VLC_SUCCESS;
>> @@ -347,7 +420,14 @@
>>
>>              if (fstat (p_sys->fd, &st) || !S_ISREG(st.st_mode))
>>                  return VLC_EGENERIC;
>> +            if (p_sys->fd_offset != -1)
>> +            {
>> +                *va_arg( args, uint64_t * ) = (off_t)p_sys->fd_size;
>> +            }
>> +            else
>> +            {
>> -            *va_arg( args, uint64_t * ) = st.st_size;
>> +                *va_arg( args, uint64_t * ) = st.st_size;
>> +            }
>>              break;
>>          }
>>
>> EOF
>>
>> On Fri, Dec 18, 2015 at 2:55 PM, Kevin Whitaker <kevin at lisnr.com> wrote:
>>
>>> Looking for feedback on this initial code to allow fd uris with offsets.
>>> I'm not often in C land, so please feel free to point out things that may
>>> not be correct.
>>>
>>>
>>> On Thu, Dec 17, 2015 at 12:10 PM, Jean-Baptiste Kempf <jb at videolan.org>
>>> wrote:
>>>
>>>> On 17 Dec, Thomas Guillem wrote :
>>>> > You should have a look at the file module in vlc:
>>>> modules/access/file.c,
>>>> > especially, the "if (!strcasecmp (p_access->psz_access, "fd"))" block
>>>> in
>>>> > the FileOpen function. Here, you should extends the module to open an
>>>> > uri that looks like "fd://<id>:offset:length"
>>>>
>>>> please use #
>>>>
>>>> With my kindest regards,
>>>>
>>>> --
>>>> Jean-Baptiste Kempf
>>>> http://www.jbkempf.com/ - +33 672 704 734
>>>> Sent from my Electronic Device
>>>> _______________________________________________
>>>> Android mailing list
>>>> Android at videolan.org
>>>> https://mailman.videolan.org/listinfo/android
>>>>
>>>
>>>
>>>
>>> --
>>>
>>> *Kevin Whitaker*
>>> Application Engineer |
>>> *LISNR*
>>> kevin at lisnr.com
>>>
>>>   website <http://www.lisnr.com/> | twitter <http://twitter.com/lisnr>
>>>  | facebook <http://facebook.com/getlisnr>
>>>
>>>
>>>  LISNR in the News:
>>>  CNBC - 2015 CNBC Disruptor 50 companies
>>> <http://www.cnbc.com/id/102609977>
>>>  Adweek - McDonald's 'Shark Tank' Winner at SXSW
>>> <http://www.adweek.com/news/technology/mcdonalds-played-game-shark-tank-sxsw-and-heres-winner-163480>
>>>  TechCrunch - R/GA Accelerator Demo Day
>>> <http://techcrunch.com/2015/02/12/at-the-techstars-rga-demo-day-ten-new-iot-companies-go-live/>
>>>
>>> *This email and any files transmitted with it are confidential and
>>> intended solely for the use of the individual or entity to whom they are
>>> addressed.  If you are not the named addressee, you should not disseminate,
>>> distribute or copy this email. Please notify the sender immediately by
>>> email if you have received this email by mistake and delete this email from
>>> your system. If you are not the intended recipient, you are notified that
>>> disclosing, copying, distributing or taking any action in reliance on the
>>> contents of this information is strictly prohibited.  Please note that any
>>> views or opinions presented in this email are solely those of the author
>>> and do not necessarily represent those of the LISNR, INC.*
>>>
>>
>>
>>
>> --
>>
>> *Kevin Whitaker*
>> Application Engineer |
>> *LISNR*
>> kevin at lisnr.com
>>
>>   website <http://www.lisnr.com/> | twitter <http://twitter.com/lisnr> |
>> facebook <http://facebook.com/getlisnr>
>>
>>
>>  LISNR in the News:
>>  CNBC - 2015 CNBC Disruptor 50 companies
>> <http://www.cnbc.com/id/102609977>
>>  Adweek - McDonald's 'Shark Tank' Winner at SXSW
>> <http://www.adweek.com/news/technology/mcdonalds-played-game-shark-tank-sxsw-and-heres-winner-163480>
>>  TechCrunch - R/GA Accelerator Demo Day
>> <http://techcrunch.com/2015/02/12/at-the-techstars-rga-demo-day-ten-new-iot-companies-go-live/>
>>
>> *This email and any files transmitted with it are confidential and
>> intended solely for the use of the individual or entity to whom they are
>> addressed.  If you are not the named addressee, you should not disseminate,
>> distribute or copy this email. Please notify the sender immediately by
>> email if you have received this email by mistake and delete this email from
>> your system. If you are not the intended recipient, you are notified that
>> disclosing, copying, distributing or taking any action in reliance on the
>> contents of this information is strictly prohibited.  Please note that any
>> views or opinions presented in this email are solely those of the author
>> and do not necessarily represent those of the LISNR, INC.*
>>
>
>
>
> --
>
> *Kevin Whitaker*
> Application Engineer |
> *LISNR*
> kevin at lisnr.com
>
>   website <http://www.lisnr.com/> | twitter <http://twitter.com/lisnr> |
> facebook <http://facebook.com/getlisnr>
>
>
>  LISNR in the News:
>  CNBC - 2015 CNBC Disruptor 50 companies
> <http://www.cnbc.com/id/102609977>
>  Adweek - McDonald's 'Shark Tank' Winner at SXSW
> <http://www.adweek.com/news/technology/mcdonalds-played-game-shark-tank-sxsw-and-heres-winner-163480>
>  TechCrunch - R/GA Accelerator Demo Day
> <http://techcrunch.com/2015/02/12/at-the-techstars-rga-demo-day-ten-new-iot-companies-go-live/>
>
> *This email and any files transmitted with it are confidential and
> intended solely for the use of the individual or entity to whom they are
> addressed.  If you are not the named addressee, you should not disseminate,
> distribute or copy this email. Please notify the sender immediately by
> email if you have received this email by mistake and delete this email from
> your system. If you are not the intended recipient, you are notified that
> disclosing, copying, distributing or taking any action in reliance on the
> contents of this information is strictly prohibited.  Please note that any
> views or opinions presented in this email are solely those of the author
> and do not necessarily represent those of the LISNR, INC.*
>



-- 

*Kevin Whitaker*
Application Engineer |
*LISNR*
kevin at lisnr.com

  website <http://www.lisnr.com/> | twitter <http://twitter.com/lisnr> |
facebook <http://facebook.com/getlisnr>


 LISNR in the News:
 CNBC - 2015 CNBC Disruptor 50 companies <http://www.cnbc.com/id/102609977>
 Adweek - McDonald's 'Shark Tank' Winner at SXSW
<http://www.adweek.com/news/technology/mcdonalds-played-game-shark-tank-sxsw-and-heres-winner-163480>
 TechCrunch - R/GA Accelerator Demo Day
<http://techcrunch.com/2015/02/12/at-the-techstars-rga-demo-day-ten-new-iot-companies-go-live/>

*This email and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed.
If you are not the named addressee, you should not disseminate, distribute
or copy this email. Please notify the sender immediately by email if you
have received this email by mistake and delete this email from your system.
If you are not the intended recipient, you are notified that disclosing,
copying, distributing or taking any action in reliance on the contents of
this information is strictly prohibited.  Please note that any views or
opinions presented in this email are solely those of the author and do not
necessarily represent those of the LISNR, INC.*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/android/attachments/20160104/48ff9c7f/attachment-0001.html>


More information about the Android mailing list