Results 1 to 5 of 5

Thread: AutoRecording module does not restart recording one stream goes down and up again

  1. #1

    Question AutoRecording module does not restart recording one stream goes down and up again

    Hi,

    I have made up an auto record module for Auto Recording which recording video in hourly schedule as mentioned in the link:
    http://www.wowza.com/forums/content....ActionNotify3)

    I am working in a origin-edge module. I have setup the auto-record module in the edge server. When I started Wowza, it started recording (which is as how it is expected to). Later after few hours.. I noticed Wowza was not recording anymore. There were .mp4 files and their respective *.mp4.tmp. The origin server was down for a while that is why the recording was stopped. But later after the origin server was started again.. the recording on edge server didn't started.


    Shouldn't the recording start automatically as the stream becomes available?

    I checked the module locally (used VLC to stream), the recording started on Wowza start and recording stopped as I stopped VLC. As i restarted VLC again.. the recording resumed.

    Below is the code I am using for AutoRecording module

    package com.ott.autorecorder;

    import java.io.File;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.HashMap;
    import java.util.Map;

    import com.wowza.wms.amf.AMFPacket;
    import com.wowza.wms.application.IApplicationInstance;
    import com.wowza.wms.application.WMSProperties;
    import com.wowza.wms.livestreamrecord.model.ILiveStreamRecord;
    import com.wowza.wms.livestreamrecord.model.ILiveStreamRecordFileVersionDelegate;
    import com.wowza.wms.livestreamrecord.model.LiveStreamRecorderMP4;
    import com.wowza.wms.media.model.MediaCodecInfoAudio;
    import com.wowza.wms.media.model.MediaCodecInfoVideo;
    import com.wowza.wms.module.IModuleOnStream;
    import com.wowza.wms.module.ModuleBase;
    import com.wowza.wms.stream.IMediaStream;
    import com.wowza.wms.stream.IMediaStreamActionNotify3;

    public class OttAutoRecorder extends ModuleBase implements IModuleOnStream {
    private Map<String, ILiveStreamRecord> recorders = new HashMap<String, ILiveStreamRecord>();
    private IApplicationInstance appInstance;

    public void onAppStart(IApplicationInstance appInstance) {
    this.appInstance = appInstance;
    }

    class StreamListener implements IMediaStreamActionNotify3 {
    public void onMetaData(IMediaStream stream, AMFPacket metaDataPacket) {
    getLogger().info("onMetaData[" + stream.getContextStr() + "]: " + metaDataPacket.toString());
    }

    public void onPauseRaw(IMediaStream stream, boolean isPause, double location) {
    getLogger().info("onPauseRaw[" + stream.getContextStr() + "]: isPause:" + isPause + " location:" + location);
    }

    public void onPause(IMediaStream stream, boolean isPause, double location) {
    getLogger().info("onPause[" + stream.getContextStr() + "]: isPause:" + isPause + " location:" + location);
    }

    public void onPlay(IMediaStream stream, String streamName, double playStart, double playLen, int playReset) {
    getLogger().info("onPlay[" + stream.getContextStr() + "]: playStart:" + playStart + " playLen:" + playLen + " playReset:" + playReset);
    }

    public void onPublish(IMediaStream stream, String streamName, boolean isRecord, boolean isAppend) {
    getLogger().info("onPublish[" + stream.getContextStr() + "]: streamName:" + streamName + " isRecord:" + isRecord + " isAppend:" + isAppend);
    if (streamName.contains("_")) {
    getLogger().info("recording for streamname " + streamName);
    // create a livestreamrecorder instance to create .mp4 files
    ILiveStreamRecord recorder = new LiveStreamRecorderMP4();
    recorder.init(appInstance);
    recorder.setRecordData(true);
    recorder.setStartOnKeyFrame(true);
    recorder.setVersionFile(true);
    recorder.setFileVersionDelegate(new ILiveStreamRecordFileVersionDelegate() {

    @Override
    public String getFilename(ILiveStreamRecord recorder) {
    String name;
    Date date = new Date();
    String dateString = new SimpleDateFormat("yyyy-MM-dd-HH.mm.ss.SSS-zzzS").format(date);

    try {
    File file = new File(recorder.getBaseFilePath());
    String oldBasePath = file.getParent();
    getLogger().info("base path: " + oldBasePath);
    String streamName = file.getName();
    String oldExt = "";
    int oldExtIndex = streamName.lastIndexOf(".");
    if (oldExtIndex >= 0) {
    oldExt = streamName.substring(oldExtIndex);
    streamName = streamName.substring(0, oldExtIndex);
    }
    File basePath = new File(oldBasePath);
    File[] filesList = basePath.listFiles();
    for (final File fileEntry : filesList) {
    getLogger().info("stream Name: " + streamName);
    getLogger().info("fileName: " + fileEntry.getName());
    String searchFilePrefix = Utils.getSameHourFileName(streamName, dateString);
    getLogger().info("search file prefix" + searchFilePrefix);
    if (fileEntry.getName().startsWith(searchFilePrefix)) {
    getLogger().info("Older file found");
    fileEntry.delete();
    }

    }

    name = oldBasePath + "/" + streamName + "_" + dateString + oldExt;
    file = new File(name);
    if (file.exists()) {
    file.delete();
    }
    } catch (Exception e) {
    // return a temp filename

    name = "temp" + dateString + ".tmp";
    }
    return name;
    }
    });

    // add it to the recorders list
    synchronized (recorders) {
    ILiveStreamRecord prevRecorder = recorders.get(streamName);
    if (prevRecorder != null)
    prevRecorder.stopRecording();
    recorders.put(streamName, recorder);
    }
    recorder.startRecordingSegmentBySchedule(stream, null, null, "0 */1 * * *");
    getLogger().info("onPublish[" + stream.getContextStr() + "]: new Recording started:" + recorder.getFilePath());
    }

    }

    public void onUnPublish(IMediaStream stream, String streamName, boolean isRecord, boolean isAppend) {
    getLogger().info("onUnPublish[" + stream.getContextStr() + "]: streamName:" + streamName + " isRecord:" + isRecord + " isAppend:" + isAppend);
    ILiveStreamRecord recorder = null;
    synchronized (recorders) {
    recorder = recorders.remove(streamName);
    }

    if (recorder != null) {
    // grab the current path to the recorded file

    String filepath = recorder.getFilePath();
    getLogger().info("filepath: " + filepath);

    // stop recording
    recorder.stopRecording();
    getLogger().info("onUnPublish[" + stream.getContextStr() + "]: File Closed:" + filepath);
    } else {
    getLogger().info("onUnPublish[" + stream.getContextStr() + "]: streamName:" + streamName + " stream recorder not found");
    }
    }

    public void onSeek(IMediaStream stream, double location) {
    getLogger().info("onSeek[" + stream.getContextStr() + "]: location:" + location);
    }

    public void onStop(IMediaStream stream) {
    getLogger().info("onStop[" + stream.getContextStr() + "]: ");
    }

    public void onCodecInfoAudio(IMediaStream stream, MediaCodecInfoAudio codecInfoAudio) {
    getLogger().info("onCodecInfoAudio[" + stream.getContextStr() + " Audio Codec" + codecInfoAudio.toCodecsStr() + "]: ");
    }

    public void onCodecInfoVideo(IMediaStream stream, MediaCodecInfoVideo codecInfoVideo) {
    getLogger().info("onCodecInfoVideo[" + stream.getContextStr() + " Video Codec" + codecInfoVideo.toCodecsStr() + "]: ");
    }
    }

    public void onStreamCreate(IMediaStream stream) {
    getLogger().info("onStreamCreate[" + stream + "]: clientId:" + stream.getClientId());
    IMediaStreamActionNotify3 actionNotify = new StreamListener();

    WMSProperties props = stream.getProperties();
    synchronized (props) {
    props.put("streamActionNotifier", actionNotify);
    }
    stream.addClientListener(actionNotify);
    }

    public void onStreamDestroy(IMediaStream stream) {
    getLogger().info("onStreamDestroy[" + stream + "]: clientId:" + stream.getClientId());

    IMediaStreamActionNotify3 actionNotify = null;
    WMSProperties props = stream.getProperties();
    synchronized (props) {
    actionNotify = (IMediaStreamActionNotify3) stream.getProperties().get("streamActionNotifier");
    }
    if (actionNotify != null) {
    stream.removeClientListener(actionNotify);
    getLogger().info("removeClientListener: " + stream.getSrc());
    }
    }
    }

  2. #2

    Default

    Hi,

    any help on this?

    Birendra

  3. #3
    Join Date
    Dec 2007
    Posts
    21,962

    Default

    The presence of .mp4.tmp files means the recordings are corrupt. It sounds like there was a network problem between the edge and origin, and neither IMediaStreamActionNotify3.onUnPublish() or IMediaStreamActionNotify3.onPublish() is running. It is not the ideal way to record. Is it possible to record on the origin?

    Richard

  4. #4

    Default

    Hi Richard,

    Many thanks for the reply.

    I agree the origin server gets down time to time... But, as per my requirement, I cannot do the recording at the origin. So, can't this be handled any other way.. so that my recording goes automatic as stream becomes available.

    Thanks,
    Birendra

  5. #5
    Join Date
    Dec 2007
    Posts
    21,962

    Default

    I'm not sure. From your description, as I said, onUnPublish is not running, so the stream is not ending properly, and onPublish is not running under these circumstances so recording doesn't restart. So I'm just not sure what you can do. Is the origin a Wowza server that you re-stream RTSP? If so, you might starting a rtsp stream from the origin on the edge in StreamManager or StartUpStreams.xml with MediaCaster type "rtp-record". It's an alternative way to try, it might handle stop and start better, but it might not make a difference

    Richard

Similar Threads

  1. Restart recording without loosing data
    By tan-tan in forum AddOn: Other AddOns
    Replies: 1
    Last Post: 11-07-2013, 04:36 PM
  2. Restart recording automatically
    By vineethkdlr in forum General Forum
    Replies: 3
    Last Post: 01-10-2013, 08:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •