📄 videostream.c
字号:
return -1; if(ichar >> 7) { SWF_warn("setVP6Dimension: first frame is interframe\n"); return -1; } if(ichar & 1) { SWF_warn("setVP6Dimension: VP60!\n"); return -1; } ichar = SWFInput_getChar(input); ichar = SWFInput_getChar(input); render_x = SWFInput_getChar(input); render_y = SWFInput_getChar(input); stream->width = render_x * 16; stream->height = render_y * 16; return 0; }static int setStreamProperties(SWFVideoStream stream) { int ret; FLVTag tag, *tag_p = NULL; stream->numFrames = FLVStream_getNumFrames(stream->flv, FLV_VIDEOTAG); while((ret = FLVStream_nextTag(stream->flv, &tag, tag_p)) == 0) { if(tag.tagType == FLV_VIDEOTAG) break; tag_p = &tag; } if(ret < 0) return -1; stream->codecId = tag.hdr.video.codec; switch (stream->codecId) { case VIDEO_CODEC_H263: ret = setH263StreamDimension(stream, &tag); stream->smoothingFlag = VIDEO_SMOOTHING; break; case VIDEO_CODEC_SCREEN: ret = setScreenStreamDimension(stream, &tag); stream->smoothingFlag = 0; break; case VIDEO_CODEC_VP6: setVP6Dimension(stream, &tag); stream->smoothingFlag = VIDEO_SMOOTHING; ret = 0; break; case VIDEO_CODEC_VP6A: case VIDEO_CODEC_SCREEN2: SWF_warn("setStreamProperties: automatic dimension setting is not working with this codec yet!\n"); ret = 0; break; default: SWF_warn("Unknown Codec %x\n", stream->codecId); ret = -1; } return ret;}static int onPlace(SWFDisplayItem item, SWFBlockList blocklist){ SWFVideoStream stream = (SWFVideoStream)SWFDisplayItem_getCharacter(item); SWFBlock video = SWFVideoStream_getVideoFrame(stream); if(video == NULL) return 0; SWFBlockList_addBlock(blocklist, video); stream->firstFrame = 0; return 1;}static int onFrame(SWFDisplayItem item, SWFBlockList blocklist){ SWFPlaceObject2Block placeVideo; SWFVideoStream stream; SWFBlock video = NULL; /* if item is new -> onInit already inserted a frame */ if(item->flags != 0) return 0; stream = (SWFVideoStream)SWFDisplayItem_getCharacter(item); if(stream->mode == SWFVIDEOSTREAM_MODE_MANUAL && stream->addFrame == 0) return 0; if(stream->mode != SWFVIDEOSTREAM_MODE_MANUAL) stream->frame++; if(stream->frame >= stream->framesLoaded) { video = SWFVideoStream_getVideoFrame(stream); if(video == NULL) return 0; } placeVideo = newSWFPlaceObject2Block(item->depth); SWFPlaceObject2Block_setRatio(placeVideo, stream->frame); SWFPlaceObject2Block_setMove(placeVideo); SWFBlockList_addBlock(blocklist, (SWFBlock)placeVideo); if(video != NULL) SWFBlockList_addBlock(blocklist, video); stream->addFrame = 0; return 2;}/** * Seek within a video stream. * * This functions allows seeking in video stream. Semantics * like SWFInput_seek(); * * Works only with SWFVIDEOSTREAM_MODE_MANUAL! * @return old video position (frame) */int SWFVideoStream_seek(SWFVideoStream stream, int frame, int whence){ int old, pos; if(stream == NULL || stream->embedded == 0) return -1; if(stream->mode != SWFVIDEOSTREAM_MODE_MANUAL) return -1; old = stream->frame; switch(whence) { case SEEK_SET: if(frame < 0 || frame >= stream->numFrames) return -1; stream->frame = frame; break; case SEEK_END: if(frame < 0 || frame >= stream->numFrames) return -1; stream->frame = stream->numFrames - frame; break; case SEEK_CUR: pos = stream->frame + frame; if(pos < 0 || pos >= stream->numFrames) return -1; break; default: return -1; } stream->addFrame = 1; return old;} /** * Display next video frame * * Works only with embedded video streams. * * @return -1 if an error happend. */int SWFVideoStream_nextFrame(SWFVideoStream stream){ if(stream == NULL || !stream->embedded) return -1; if(stream->mode != SWFVIDEOSTREAM_MODE_MANUAL) return -1; if(stream->addFrame == 1 || stream->firstFrame == 1) return 0; stream->addFrame = 1; stream->frame++; return 0;}/** * switch video stream frame mode * If the mode == SWFVIDEOSTREAM_MODE_AUTO (default) every swfmovie * frame a video frame is added. * In SWFVIDEOSTREAM_MODE_MANUAL mode, the user needs to call * SWFVideoStream_nextFrame() to change the video's frame. * * Works only with embedded video streams. * * @return the previous mode or -1 if an invalid mode was passed. */int SWFVideoStream_setFrameMode(SWFVideoStream stream, int mode){ int oldmode; if(stream == NULL || !stream->embedded) return -1; oldmode = stream->mode; switch(mode) { case SWFVIDEOSTREAM_MODE_AUTO: stream->mode = mode; return oldmode; case SWFVIDEOSTREAM_MODE_MANUAL: stream->mode = mode; return oldmode; default: SWF_warn("SWFVideoStream_setFrameMode: mode %i is unknown", mode); return -1; }}/* * create a new SWFVideoSteam object * This function creates a new videostream object from a FLV-file. * Takes a SWFInput object as argument. * Be aware: You need to keep the SWFInput valid until the movie is generated via save() or output()! */SWFVideoStreamnewSWFVideoStream_fromInput(SWFInput input) { SWFBlock block; SWFVideoStream stream; if(!input) return NULL; stream = (SWFVideoStream)malloc(sizeof(struct SWFVideoStream_s)); if(!stream) return NULL; block = (SWFBlock)stream; SWFCharacterInit((SWFCharacter)stream); CHARACTERID(stream) = ++SWF_gNumCharacters; ((SWFCharacter)stream)->onFrame = onFrame; ((SWFCharacter)stream)->onPlace = onPlace; block->type = SWF_DEFINEVIDEOSTREAM; block->writeBlock = writeSWFVideoStreamToMethod; block->complete = completeSWFVideoStream; block->dtor = (destroySWFBlockMethod)destroySWFVideoStream; stream->flv = FLVStream_fromInput(input); if(stream->flv == NULL) { free(stream); return NULL; } stream->lastTag = NULL; stream->lastFrame = 0; stream->frame = 0; stream->embedded = 1; stream->mode = SWFVIDEOSTREAM_MODE_AUTO; stream->addFrame = 0; stream->framesLoaded = 0; stream->firstFrame = 1; stream->width = VIDEO_DEF_WIDTH; stream->height = VIDEO_DEF_HEIGHT; if (setStreamProperties(stream) < 0) { free(stream); return NULL; } return stream;}/* * creates a new SWFVideoStream object * This function creates an empty videostream object. This object can be adressed via * ActionScript to connect and display a streamed video (progessive download / rtmp). */SWFVideoStream newSWFVideoStream() { SWFBlock block; SWFVideoStream stream = (SWFVideoStream)malloc(sizeof(struct SWFVideoStream_s)); if(!stream) return NULL; block = (SWFBlock)stream; SWFCharacterInit((SWFCharacter)stream); CHARACTERID(stream) = ++SWF_gNumCharacters; block->type = SWF_DEFINEVIDEOSTREAM; block->writeBlock = writeSWFVideoStreamToMethod; block->complete = completeSWFVideoStream; block->dtor = (destroySWFBlockMethod)destroySWFVideoStream; stream->flv = NULL; stream->lastTag = NULL; stream->frame = 0; stream->embedded = 0; stream->numFrames = -1; stream->width = VIDEO_DEF_WIDTH; stream->height = VIDEO_DEF_HEIGHT; return stream;} /* * create a new SWFVideoSteam object * This function creates a new videostream object from a FLV-file. * Takes a FILE * as argument. * Be aware: You need to keep the FILE open until the movie is generated via save() or output()! */SWFVideoStream newSWFVideoStream_fromFile(FILE *f /* FILE pointer to a FLV-file */) { return newSWFVideoStream_fromInput(newSWFInput_file(f));}/* * sets video dimension * This function set width and height for streamed videos * Works only _streamed_ videos (progressive download or rtmp) */void SWFVideoStream_setDimension(SWFVideoStream stream /* stream object */, int width, /* width in px */ int height /* height in px */) { if(!stream->embedded) { stream->width = width; stream->height = height; }}/* * returns the number of video-frames * This function returns the number of video-frames of a SWFVideoStream. * Works only for embedded streams! */int SWFVideoStream_getNumFrames(SWFVideoStream stream /* Embedded video stream */) { if(!stream) return -1; return stream->numFrames;}/* * returns 1 if embedded video stream has also an audio stream * This functions test if the embedded FLV stream also has audio-data. */int SWFVideoStream_hasAudio(SWFVideoStream stream /* Embedded video stream */){ if(stream != NULL && stream->flv != NULL && stream->flv->has_audio) return 1; return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -