"Video development" "Live555" camera capture, 264 encoded, live555 Live (0)

Source: Internet
Author: User
Tags fread

See the live555

1. First, you need to modify the live555 to define the class that gets the source directly from memory instead of reading the source from the file.

The class you implement is named H264framedlivesource

/* * Filename:H264FramedLiveSource.hh * auther:chenbin * Create DATE:2013/1/22 * * #ifndef _h264framedlivesource_hh #define _H264FRAMEDLIVESOURCE_HH #include <FramedSource.hh> class 
        H264framedlivesource:public Framedsource {public:static h264framedlivesource* createNew (usageenvironment& env, 

Char const* fileName, unsigned preferredframesize = 0, unsigned playtimeperframe = 0); Protected:h264framedlivesource (usageenvironment& env, char const* fileName, unsigned PREFERREDFR
    Amesize, unsigned playtimeperframe);

Called Only by CreateNew () ~h264framedlivesource ();
    Private://redefined virtual functions:virtual void Dogetnextframe ();

int Transportdata (unsigned char* to, unsigned maxSize);
Protected:file *FP;

}; #endif 
/* * Filename:H264FramedLiveSource.cpp * AUTHER:MLJ * Create DATE:2013/1/22 */#include "H264FramedLiveSource.h H "H264framedlivesource::h264framedlivesource (usageenvironment& env, char const* fileName, unsigned PR 
Eferredframesize, unsigned playtimeperframe): Framedsource (env) {fp = fopen (FileName, "RB");
                                           } h264framedlivesource* h264framedlivesource::createnew (usageenvironment& env, 
                                           Char const* fileName, unsigned preferredframesize/*= 0*/, unsigned playtimeperframe/*= 0*/) {h264framedlivesource* newsource = new h264framed
 
    LiveSource (env, FileName, Preferredframesize, playtimeperframe);
return newsource;


} h264framedlivesource::~h264framedlivesource () {fclose (FP);}
    Long FileSize (FILE *stream) {long curpos, length;
    CurPos = Ftell (stream);
 Fseek (Stream, 0L, seek_end);   Length = Ftell (stream);
    Fseek (Stream, CurPos, seek_set);
return length; } void H264framedlivesource::d ogetnextframe () {if (filesize (FP) > fmaxsize) fframesize = Fread (Fto,1,fmax 
    SIZE,FP);
        else {fframesize = Fread (fto,1,filesize (FP), FP);
    Fseek (FP, 0, Seek_set);
    }//fframesize = Fmaxsize; Nexttask () = EnviR (). TaskScheduler (). Scheduledelayedtask (0, (taskfunc*) framedsource::aftergetting, this);//indicates a delay of 0 seconds
Then execute the aftergetting function return; }

In H264framedlivesource::d ogetnextframe (), the content to be sent is copied to FTo, with a maximum of fmaxsize,fframesize indicating how many bytes are actually sent. Here for the time being read from the file as a test.

2. Define your own Servermedia

/* * Filename:H264LiveVideoServerMediaSubssion.hh * AUTHER:MLJ * Create DATE:2013/1 /22 */#ifndef _h264_live_video_server_media_subsession_hh #define _H264_LIVE_VIDEO_SERVER_MEDIA_SUBSESSION_HH # Include "H264videofileservermediasubsession.hh" class H264livevideoservermediasubssion:public h264videofileservermediasubsession {public:static h264livevideoservermediasubssion* createNew (UsageEnvironment&am P

Env, Char const* fileName, Boolean reusefirstsource); Protected://We ' re a virtual base class H264livevideoservermediasubssion (usageenvironment& env, char const* Filena
   Me, Boolean Reusefirstsource);

~h264livevideoservermediasubssion ();
                          Protected://redefined virtual functions framedsource* createnewstreamsource (unsigned clientsessionid,
unsigned& estbitrate);

Public:char ffilename[100];


}; #endif 
/* * Filename:H264LiveVideoServerMediaSubssion.cpp * auther:chenbin * Create date:2012/11/29 */#include "h264live

Videoservermediasubssion.hh "#include" h264framedlivesource.hh "#include" h264videostreamframer.hh "
                                             h264livevideoservermediasubssion* h264livevideoservermediasubssion::createnew (UsageEnvironment& env, Char const* fileName, Boolean Reusefirstsource

{return new h264livevideoservermediasubssion (env, FileName, Reusefirstsource);} H264livevideoservermediasubssion::h264livevideoservermediasubssion (usageenvironment& env, char const* fileName , Boolean Reusefirstsource): H264videofileservermediasubsession (env, FileName, Reusefirstsource) {strcpy (Ffilenam
E,filename); } h264livevideoservermediasubssion::~h264livevideoservermediasubssion () {} framedsource* H264livevideoservermediasubssion::createnewstreamsource (unsigned clientsessionid, unsigned& EStbitrate) {/* remain to do:assign estbitrate */estbitrate = +,//kbps, estimate//Create the video
    source:h264framedlivesource* LiveSource = h264framedlivesource::createnew (EnviR (), ffilename);
    if (LiveSource = = null) {return null; }//Create a framer for the Video Elementary Stream:return h264videostreamframer::createnew (EnviR (), LiveSource
); }

3. Main function

/********** This library are free
software, you can redistribute it and/or modify it under the terms of the
GNU Les Ser general public License as published by the free
software Foundation; either version 2.1 of the License, or R
option) any later version. (see 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.