Motion - Netcam Content Auth Patch
You are here: Foswiki>Motion Web>NetcamContentAuthPatch (16 Jun 2008, AngelCarpintero)Edit Attach

Support of Network camera with Content-Auth header in stream

Description of Patch

Hi, my name is Lucio Dona' and I am using Motion with a Grandtec Grand IP Camera III.

This camera was supported by Motion only in still image mode, and I am sending to you a simple modification to apply to netcam. c to support streaming.

After this modification, you can use the /video.cgi path on the camera instead of /still.jpg .

Well, the problem was that this cam sends out a "Content-Auth" field in the streaming header and this field was not parsed by netcam_read_next_header.

The modification is very easy ; I cannot send it to you in patch format because I am still working on it, and I applied also V4L2 and tracking patches...

so please have a look at the piece of code I am sending to you and let me know if you think it could be interesting.

BTW, I also succeeded in connecting a Logitech Sphere to Motion, the new model uses uvcvideo driver and so I applied V4L2 patches and tracking patches I found on your wiki.

Many compliments for your work !!

Best regards

Lucio Dona'

Installation of Patch

* Get svn version of motion and apply the patch from motion directory:

   
 patch < NetcamContentAuthPatch.diff

-- AngelCarpintero - 14 Jun 2007

Change History of Patch

  • 1.0 Initial revision

The altered code

// LD ADD BEGIN
/**
 * netcam_check_content_auth
 *
 *    Analyse an HTTP-header line to see if it is a Content-auth
 *
 * Parameters:
 *
 *      header          Pointer to a string containing the header line
 *
 * Returns:
 *      -1              Not a Content-auth line
 *      1               auth code line
 *
 */
static int netcam_check_content_auth(char *header)
{
   char *content_auth = NULL;

   if (!header_process(header, "Content-Auth", http_process_type, &content_auth))
      return -1;

   if (content_auth)
      free(content_auth);

   return 1;
}
// LD ADD END

/**
 * netcam_read_next_header
 *
 *      Read the next header record from the camera.
 *
 * Parameters
 *
 *      netcam          pointer to a netcam_context
 *
 * Returns:             0 for success, -1 if any error
 *
 */
static int netcam_read_next_header(netcam_context_ptr netcam)
{
   int retval;
   char *header;

   /*
    * return if not connected
    */
   if (netcam->sock == -1) return -1;
   /*
    * We are expecting a header which *must* contain a mime-type of
    * image/jpeg, and *might* contain a Content-Length.
    *
    * If this is a "streaming" camera, the header *must* be preceded
    * by a "boundary" string.
    *
    */
   netcam->caps.content_length = 0;
   /*
    * If this is a "streaming" camera, the stream header must be
    * preceded by a "boundary" string
    */
   if (netcam->caps.streaming) {
      while (1) {
         retval = header_get(netcam, &header, HG_NONE);

         if (retval != HG_OK) {
            motion_log(LOG_ERR, 0, "Error reading image header");
            free(header);
            return -1;
         }

         retval = (strstr(header, netcam->boundary) == NULL);
         free(header);

         if (!retval)
            break;
      }
   }

   while (1) {
      retval = header_get(netcam, &header, HG_NONE);

      if (retval != HG_OK) {
         motion_log(LOG_ERR, 0, "Error reading image header");
         free(header);
         return -1;
      }

      if (*header == 0)
         break;

      if ((retval = netcam_check_content_type(header)) >= 0) {
         if (retval != 1) {
            motion_log(LOG_ERR, 0, "Header not JPEG");
            free(header);
            return -1;
         }
      }

      if ((retval = (int) netcam_check_content_length(header)) > 0) {
         netcam->caps.content_length = 1;       /* set flag */
         netcam->receiving->content_length = (int) retval;
      }

// LD ADD BEGIN
      if ((retval = (int) netcam_check_content_auth(header)) > 0) {
      break;
      }
// LD ADD END

      free(header);
   }

   if (debug_level > CAMERA_INFO)
      motion_log(-1, 0, "Found image header record");

   free(header);
   return 0;
}

Discussion and Comments


Hello. When I use /video.cgi source I'm still getting error like:
[1] Not a JPEG file: starts with 0x0d 0x0a
[1] libjpeg decompression failure on first frame - giving up!

I've got SVN version with NetcamContentAuthPatch.diff from bottom of this site. What is wrong? Sorry for my english cry

-- MateuszKnapik - 13 Jun 2007

Answer moved here :

http://www.lavrsen.dk/twiki/bin/view/Motion/SupportQuestion2007x06x13x094424

-- AngelCarpintero - 14 Jun 2007

Hi, is this patch still required with the most recent firmware? I got the most recent firmware from http://blogs.unbolt.net/index.php/brinley/2007/10/18/grandtec_grand_ip_camera_3_firmware_upda and mjpg seems to be working fine

-- ClarkBang - 18 Nov 2007


Thanks Crark , patch cancelled.

-- AngelCarpintero - 16 Jun 2008


Topic revision: r6 - 16 Jun 2008, AngelCarpintero
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Please do not email Kenneth for support questions (read why). Use the Support Requests page or join the Mailing List.
This website only use harmless session cookies. See Cookie Policy for details. By using this website you accept the use of these cookies.