Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef __ffmpegvideo_H__
- #define __ffmpegvideo_H__
- #pragma once
- //#include "cocos2d.h"
- //#include "cocostudio/CocoStudio.h"
- //#include <string>
- //#include "cocostudio/CCComExtensionData.h"
- //#include <vector>
- //#include <sstream>
- //#include <utility>
- //#include <algorithm>
- //#include <iostream>
- //#include <fstream>
- #include "cocos2d\cocos\2d\CCSprite.h"
- extern "C" {
- #include <libavformat\avformat.h>
- #include <libavcodec\avcodec.h>
- #include <libswscale\swscale.h>
- }
- #include "shader_sampler.h"
- class video : public cocos2d::Sprite {
- public:
- static unsigned int totalVideoPlayers;
- video(std::string, cocos2d::Sprite* = nullptr);
- ~video();
- struct frameData {
- frameData() {};
- ~frameData() {};
- AVFrame* frame;
- AVPacket* pkt;
- unsigned char* pdata;
- bool needsRefill = true;
- std::string name = "";
- std::mutex bufferLock;
- ///unsigned int crrFrame
- GLuint pboid = 0;
- };
- GLuint pboids[2];
- void actualDraw();
- //returns pixel data
- ///unsigned char* getNextFrame();
- inline unsigned int getCrrFrameIndex() { return framecount; }
- inline int getHeight() { return height; }
- inline int getWidth() { return width; }
- //only internally resets video, doesn't output frame!
- ///void restartVideoPlay(bool read = true);
- //helpers
- bool isPlaying = false;
- ///unsigned char* getCurrentRBGConvertedFrame();
- //unsigned char* getCurrentRBGAConvertedFrame(); //alpha
- unsigned char* getNextFrame(frameData*);
- unsigned char* getCurrentRBGConvertedFrame(frameData*);
- void restartVideoPlay(video::frameData*);
- void freeData();
- void play();
- void pause();
- //void resume //resume is same as play
- void stop();
- bool repeat = true;
- void draw(cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t flags);
- void decodeLoop();
- std::mutex pxDataMtx;
- void setRepeats(int);
- std::string hideWithEvent = "";
- std::string showWithEvent = "";
- ///unsigned char*
- frameData* getData();
- private:
- int repeatTimes = 1;
- UINT32 loopedTimes = 0;
- bool display = false;
- // declare format and codec contexts, also codec for decoding
- AVFormatContext *format_contex = NULL;
- AVCodecContext *codec_contex = NULL;
- AVCodec *Codec = NULL;
- std::string infilename = ""; //wmv or ANY format
- int VideoStreamIndex = -1;
- int width, height;
- //FILE *fin = NULL;
- AVFrame* oframe = NULL; //original decoded frame
- AVFrame* cframe = NULL; //converted frame
- AVPacket *pkt = NULL;
- uint8_t *buffer = nullptr;
- //GLuint tex_id;
- //GLuint buff_id;
- unsigned int framecount = 0;
- void video_init();
- AVFrame* decode(AVCodecContext* cc, AVFrame* frame, AVPacket* pack);
- unsigned int VBO, VAO, EBO;
- unsigned int texture1;//, texture2;
- Shader *ourShader = nullptr;
- //original properties
- bool transfer = false;
- bool wasVisible = true;
- float org_rotation = -1;
- float org_scaleX = -1;
- float org_scaleY = -1;
- GLubyte org_opacity;
- //float org_scaleX = -1;
- cocos2d::Vec2 org_anchor;
- cocos2d::Vec2 org_pos;
- cocos2d::Size org_size;
- cocos2d::BlendFunc org_blend;
- int32_t org_zorder;
- frameData buf1;
- frameData buf2;
- public:
- cocos2d::CustomCommand* _customCommand = nullptr;
- cocos2d::Sprite* holdersprite = nullptr; //not actual holder
- bool shouldhide = false;
- bool firstBuff = true;
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement