Skip to content

Commit

Permalink
Merge pull request #1 from ZoneMinder/storageareas
Browse files Browse the repository at this point in the history
Storageareas
  • Loading branch information
bhaal2 authored Sep 20, 2016
2 parents c74af40 + ae80fd4 commit 78b0868
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 73 deletions.
2 changes: 1 addition & 1 deletion scripts/ZoneMinder/lib/ZoneMinder/Storage.pm
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ sub Path {
$_[0]{Path} = $_[1];
}
if ( ! ( $_[0]{Id} or $_[0]{Path} ) ) {
$_[0]{Path} = $Config{ZM_DIR_EVENTS};
$_[0]{Path} = ($Config{ZM_DIR_EVENTS}=~/^\//) ? $Config{ZM_DIR_EVENTS} : ($Config{ZM_PATH_WEB}.'/'.$Config{ZM_DIR_EVENTS})
}
return $_[0]{Path};
} # end sub Path
Expand Down
52 changes: 32 additions & 20 deletions src/zm_ffmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,13 @@ int hacked_up_context2_for_older_ffmpeg(AVFormatContext **avctx, AVOutputFormat
static void zm_log_fps(double d, const char *postfix) {
uint64_t v = lrintf(d * 100);
if (!v) {
Debug(3, "%1.4f %s", d, postfix);
Debug(1, "%1.4f %s", d, postfix);
} else if (v % 100) {
Debug(3, "%3.2f %s", d, postfix);
Debug(1, "%3.2f %s", d, postfix);
} else if (v % (100 * 1000)) {
Debug(3, "%1.0f %s", d, postfix);
Debug(1, "%1.0f %s", d, postfix);
} else
Debug(3, "%1.0fk %s", d / 1000, postfix);
Debug(1, "%1.0fk %s", d / 1000, postfix);
}

/* "user interface" functions */
Expand All @@ -429,17 +429,17 @@ void zm_dump_stream_format(AVFormatContext *ic, int i, int index, int is_output)
AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0);

avcodec_string(buf, sizeof(buf), st->codec, is_output);
Debug(3, " Stream #%d:%d", index, i);
Debug(1, " Stream #%d:%d", index, i);

/* the pid is an important information, so we display it */
/* XXX: add a generic system */
if (flags & AVFMT_SHOW_IDS)
Debug(3, "[0x%x]", st->id);
Debug(1, "[0x%x]", st->id);
if (lang)
Debug(3, "(%s)", lang->value);
Debug(1, "(%s)", lang->value);
av_log(NULL, AV_LOG_DEBUG, ", %d, %d/%d", st->codec_info_nb_frames,
st->time_base.num, st->time_base.den);
Debug(3, ": %s", buf);
Debug(1, ": %s", buf);

if (st->sample_aspect_ratio.num && // default
av_cmp_q(st->sample_aspect_ratio, st->codec->sample_aspect_ratio)) {
Expand All @@ -448,7 +448,7 @@ void zm_dump_stream_format(AVFormatContext *ic, int i, int index, int is_output)
st->codec->width * (int64_t)st->sample_aspect_ratio.num,
st->codec->height * (int64_t)st->sample_aspect_ratio.den,
1024 * 1024);
Debug(3, ", SAR %d:%d DAR %d:%d",
Debug(1, ", SAR %d:%d DAR %d:%d",
st->sample_aspect_ratio.num, st->sample_aspect_ratio.den,
display_aspect_ratio.num, display_aspect_ratio.den);
}
Expand All @@ -470,28 +470,40 @@ void zm_dump_stream_format(AVFormatContext *ic, int i, int index, int is_output)
}

if (st->disposition & AV_DISPOSITION_DEFAULT)
Debug(3, " (default)");
Debug(1, " (default)");
if (st->disposition & AV_DISPOSITION_DUB)
Debug(3, " (dub)");
Debug(1, " (dub)");
if (st->disposition & AV_DISPOSITION_ORIGINAL)
Debug(3, " (original)");
Debug(1, " (original)");
if (st->disposition & AV_DISPOSITION_COMMENT)
Debug(3, " (comment)");
Debug(1, " (comment)");
if (st->disposition & AV_DISPOSITION_LYRICS)
Debug(3, " (lyrics)");
Debug(1, " (lyrics)");
if (st->disposition & AV_DISPOSITION_KARAOKE)
Debug(3, " (karaoke)");
Debug(1, " (karaoke)");
if (st->disposition & AV_DISPOSITION_FORCED)
Debug(3, " (forced)");
Debug(1, " (forced)");
if (st->disposition & AV_DISPOSITION_HEARING_IMPAIRED)
Debug(3, " (hearing impaired)");
Debug(1, " (hearing impaired)");
if (st->disposition & AV_DISPOSITION_VISUAL_IMPAIRED)
Debug(3, " (visual impaired)");
Debug(1, " (visual impaired)");
if (st->disposition & AV_DISPOSITION_CLEAN_EFFECTS)
Debug(3, " (clean effects)");
Debug(3, "\n");
Debug(1, " (clean effects)");
Debug(1, "\n");

//dump_metadata(NULL, st->metadata, " ");

//dump_sidedata(NULL, st, " ");
}

int check_sample_fmt(AVCodec *codec, enum AVSampleFormat sample_fmt) {
const enum AVSampleFormat *p = codec->sample_fmts;

while (*p != AV_SAMPLE_FMT_NONE) {
if (*p == sample_fmt)
return 1;
else Debug(2, "Not %s", av_get_sample_fmt_name( *p ) );
p++;
}
return 0;
}
2 changes: 2 additions & 0 deletions src/zm_ffmpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,6 @@ void zm_dump_stream_format(AVFormatContext *ic, int i, int index, int is_output)
#define zm_avcodec_decode_video(context, rawFrame, frameComplete, packet ) avcodec_decode_video( context, rawFrame, frameComplete, packet->data, packet->size)
#endif

int check_sample_fmt(AVCodec *codec, enum AVSampleFormat sample_fmt);

#endif // ZM_FFMPEG_H
54 changes: 33 additions & 21 deletions src/zm_ffmpeg_camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,15 @@ int FfmpegCamera::OpenFfmpeg() {
} else {
Debug(1, "Video Found decoder");
zm_dump_stream_format(mFormatContext, mVideoStreamId, 0, 0);
// Open the codec
#if !LIBAVFORMAT_VERSION_CHECK(53, 8, 0, 8, 0)
Debug ( 1, "Calling avcodec_open" );
if (avcodec_open(mVideoCodecContext, mVideoCodec) < 0)
#else
Debug ( 1, "Calling avcodec_open2" );
if (avcodec_open2(mVideoCodecContext, mVideoCodec, 0) < 0)
#endif
Fatal( "Unable to open codec for video stream from %s", mPath.c_str() );
}

if (mAudioStreamId >= 0) {
Expand All @@ -365,20 +374,20 @@ int FfmpegCamera::OpenFfmpeg() {
} else {
Debug(1, "Audio Found decoder");
zm_dump_stream_format(mFormatContext, mAudioStreamId, 0, 0);
}
}

//

// Open the codec
#if !LIBAVFORMAT_VERSION_CHECK(53, 8, 0, 8, 0)
Debug ( 1, "Calling avcodec_open" );
if (avcodec_open(mVideoCodecContext, mVideoCodec) < 0)
if (avcodec_open(mAudioCodecContext, mAudioCodec) < 0)
#else
Debug ( 1, "Calling avcodec_open2" );
if (avcodec_open2(mVideoCodecContext, mVideoCodec, 0) < 0)
if (avcodec_open2(mAudioCodecContext, mAudioCodec, 0) < 0)
#endif
Fatal( "Unable to open codec for video stream from %s", mPath.c_str() );
}
}

//


Debug ( 1, "Opened codec" );

Expand Down Expand Up @@ -556,7 +565,7 @@ int FfmpegCamera::CaptureAndRecord( Image &image, bool recording, char* event_fi
while ( !frameComplete ) {
// We are now allocating dynamically because we need to queue these and may go out of scope.
AVPacket *packet = (AVPacket *)av_malloc(sizeof(AVPacket));
av_init_packet( packet);
av_init_packet( packet );
Debug(5, "Before av_read_frame");
ret = av_read_frame( mFormatContext, packet );
Debug(5, "After av_read_frame (%d)", ret );
Expand Down Expand Up @@ -627,10 +636,11 @@ Debug(5, "After av_read_frame (%d)", ret );
while ( ( queued_packet = packetqueue.popPacket() ) ) {
packet_count += 1;
//Write the packet to our video store
Debug(2, "Writing queued packet stream: %d KEY %d", queued_packet->stream_index, packet->flags & AV_PKT_FLAG_KEY );
if ( queued_packet->stream_index == mVideoStreamId ) {
ret = videoStore->writeVideoFramePacket( queued_packet, mFormatContext->streams[mVideoStreamId]);
} else if ( queued_packet->stream_index == mAudioStreamId ) {
//ret = videoStore->writeAudioFramePacket(&queued_packet, mFormatContext->streams[mAudioStreamId]);
ret = videoStore->writeAudioFramePacket( queued_packet, mFormatContext->streams[mAudioStreamId]);
} else {
Warning("Unknown stream id in queued packet (%d)", queued_packet->stream_index );
ret = -1;
Expand All @@ -643,28 +653,30 @@ Debug(5, "After av_read_frame (%d)", ret );
Debug(2, "Wrote %d queued packets", packet_count );
} // end if ! wasRecording

//Write the packet to our video store
int ret = videoStore->writeVideoFramePacket( packet, mFormatContext->streams[mVideoStreamId] );
if ( ret < 0 ) { //Less than zero and we skipped a frame
zm_av_unref_packet( packet );
return 0;
}
} else {
// Not recording
if ( videoStore ) {
Info("Deleting videoStore instance");
delete videoStore;
videoStore = NULL;
}
} // end if

//Buffer video packets
if ( packet->flags & AV_PKT_FLAG_KEY ) {
packetqueue.clearQueue();
}
packetqueue.queuePacket(packet);
//Buffer video packets, since we are not recording
if ( (packet->stream_index == mVideoStreamId) && ( packet->flags & AV_PKT_FLAG_KEY ) ) {
packetqueue.clearQueue();
}
packetqueue.queuePacket(packet);
} // end if

if ( packet->stream_index == mVideoStreamId ) {
if ( videoStore ) {
//Write the packet to our video store
int ret = videoStore->writeVideoFramePacket( packet, mFormatContext->streams[mVideoStreamId] );
if ( ret < 0 ) { //Less than zero and we skipped a frame
zm_av_unref_packet( packet );
return 0;
}
}
ret = zm_avcodec_decode_video( mVideoCodecContext, mRawFrame, &frameComplete, packet );
if ( ret < 0 ) {
av_strerror( ret, errbuf, AV_ERROR_MAX_STRING_SIZE );
Expand Down
6 changes: 3 additions & 3 deletions src/zm_packetqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#ifndef ZM_PACKETQUEUE_H
#define ZM_PACKETQUEUE_H

#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/containers/map.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
//#include <boost/interprocess/managed_shared_memory.hpp>
//#include <boost/interprocess/containers/map.hpp>
//#include <boost/interprocess/allocators/allocator.hpp>
#include <queue>

extern "C" {
Expand Down
Loading

0 comments on commit 78b0868

Please sign in to comment.