MCPcopy Create free account
hub / github.com/Motion-Project/motion / netcam_image_read_complete

Function netcam_image_read_complete

src/netcam_http.c:878–923  ·  view source on GitHub ↗

* Publish new image * * Moves the image in 'receiving' into 'latest' and updates last frame time */

Source from the content-addressed store, hash-verified

876 * Moves the image in 'receiving' into 'latest' and updates last frame time
877 */
878void netcam_image_read_complete(netcam_context_ptr netcam)
879{
880 struct timeval curtime;
881 netcam_buff *xchg;
882
883 if (gettimeofday(&curtime, NULL) < 0) {
884 MOTION_LOG(WRN, TYPE_NETCAM, SHOW_ERRNO, "gettimeofday");
885 }
886
887 netcam->receiving->image_time = curtime;
888 /*
889 * Calculate our "running average" time for this netcam's
890 * frame transmissions (except for the first time).
891 * Note that the average frame time is held in microseconds.
892 */
893 if (netcam->last_image.tv_sec) {
894 netcam->av_frame_time = ((9.0 * netcam->av_frame_time) + 1000000.0 *
895 (curtime.tv_sec - netcam->last_image.tv_sec) +
896 (curtime.tv_usec- netcam->last_image.tv_usec)) / 10.0;
897
898 /* The following floods the log. Comment out until it is needed. */
899 //MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO, "Calculated frame time %f", netcam->av_frame_time);
900 }
901
902 netcam->last_image = curtime;
903
904 /*
905 * read is complete - set the current 'receiving' buffer atomically
906 * as 'latest', and make the buffer previously in 'latest' become
907 * the new 'receiving'.
908 */
909 pthread_mutex_lock(&netcam->mutex);
910
911 xchg = netcam->latest;
912 netcam->latest = netcam->receiving;
913 netcam->receiving = xchg;
914 netcam->imgcnt++;
915
916 /*
917 * We have a new frame ready. We send a signal so that
918 * any thread (e.g. the motion main loop) waiting for the
919 * next frame to become available may proceed.
920 */
921 pthread_cond_signal(&netcam->pic_ready);
922 pthread_mutex_unlock(&netcam->mutex);
923}
924
925/**
926 * netcam_read_html_jpeg

Callers 4

netcam_read_html_jpegFunction · 0.85
netcam_read_mjpg_jpegFunction · 0.85
netcam_read_file_jpegFunction · 0.85
netcam_read_ftp_jpegFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected