Advertisement
Guest User

video.h

a guest
Jun 12th, 2019
555
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.34 KB | None | 0 0
  1. #ifndef __ffmpegvideo_H__
  2. #define __ffmpegvideo_H__
  3.  
  4. #pragma once
  5.  
  6. //#include "cocos2d.h"
  7. //#include "cocostudio/CocoStudio.h"
  8. //#include <string>
  9. //#include "cocostudio/CCComExtensionData.h"
  10.  
  11. //#include <vector>
  12. //#include <sstream>
  13. //#include <utility>
  14. //#include <algorithm>
  15. //#include <iostream>
  16.  
  17. //#include <fstream>
  18. #include "cocos2d\cocos\2d\CCSprite.h"
  19.  
  20. extern "C" {
  21. #include <libavformat\avformat.h>
  22. #include <libavcodec\avcodec.h>
  23. #include <libswscale\swscale.h>
  24. }
  25. #include "shader_sampler.h"
  26.  
  27. class video : public cocos2d::Sprite {
  28.  
  29. public:
  30.     static unsigned int totalVideoPlayers;
  31.  
  32.  
  33.     video(std::string, cocos2d::Sprite* = nullptr);
  34.     ~video();
  35.  
  36.  
  37.     struct frameData {
  38.         frameData() {};
  39.         ~frameData() {};
  40.  
  41.         AVFrame* frame;
  42.         AVPacket* pkt;
  43.         unsigned char* pdata;
  44.         bool needsRefill = true;
  45.         std::string name = "";
  46.  
  47.         std::mutex bufferLock;
  48.  
  49.         ///unsigned int crrFrame
  50.         GLuint pboid = 0;
  51.     };
  52.  
  53.     GLuint pboids[2];
  54.  
  55.  
  56.     void actualDraw();
  57.  
  58.     //returns pixel data
  59.     ///unsigned char* getNextFrame();
  60.  
  61.     inline unsigned int getCrrFrameIndex() { return framecount; }
  62.     inline int getHeight() { return height; }
  63.     inline int getWidth() { return width; }
  64.  
  65.     //only internally resets video, doesn't output frame!
  66.     ///void restartVideoPlay(bool read = true);
  67.  
  68.  
  69.     //helpers
  70.     bool isPlaying = false;
  71.     ///unsigned char* getCurrentRBGConvertedFrame();
  72.     //unsigned char* getCurrentRBGAConvertedFrame(); //alpha
  73.  
  74.     unsigned char* getNextFrame(frameData*);
  75.     unsigned char* getCurrentRBGConvertedFrame(frameData*);
  76.     void restartVideoPlay(video::frameData*);
  77.  
  78.  
  79.     void freeData();
  80.     void play();
  81.     void pause();
  82.     //void resume //resume is same as play
  83.     void stop();
  84.  
  85.     bool repeat = true;
  86.  
  87.     void draw(cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t flags);
  88.  
  89.     void decodeLoop();
  90.  
  91.     std::mutex pxDataMtx;
  92.  
  93.     void setRepeats(int);
  94.  
  95.     std::string hideWithEvent = "";
  96.     std::string showWithEvent = "";
  97.  
  98.     ///unsigned char*
  99.     frameData* getData();
  100.  
  101. private:
  102.  
  103.     int repeatTimes = 1;
  104.     UINT32 loopedTimes = 0;
  105.  
  106.     bool display = false;
  107.  
  108.     // declare format and codec contexts, also codec for decoding
  109.     AVFormatContext *format_contex = NULL;
  110.     AVCodecContext *codec_contex = NULL;
  111.     AVCodec *Codec = NULL;
  112.  
  113.     std::string infilename = ""; //wmv or ANY format
  114.     int VideoStreamIndex = -1;
  115.     int width, height;
  116.  
  117.     //FILE *fin = NULL;
  118.  
  119.     AVFrame* oframe = NULL; //original decoded frame
  120.     AVFrame* cframe = NULL; //converted frame
  121.     AVPacket *pkt = NULL;
  122.     uint8_t *buffer = nullptr;
  123.  
  124.     //GLuint tex_id;
  125.     //GLuint buff_id;
  126.  
  127.     unsigned int framecount = 0;
  128.    
  129.  
  130.     void video_init();
  131.     AVFrame* decode(AVCodecContext* cc, AVFrame* frame, AVPacket* pack);
  132.  
  133.     unsigned int VBO, VAO, EBO;
  134.  
  135.     unsigned int texture1;//, texture2;
  136.  
  137.    
  138.     Shader *ourShader = nullptr;
  139.  
  140.     //original properties
  141.     bool transfer = false;
  142.     bool wasVisible = true;
  143.     float org_rotation = -1;
  144.     float org_scaleX = -1;
  145.     float org_scaleY = -1;
  146.     GLubyte org_opacity;
  147.     //float org_scaleX = -1;
  148.     cocos2d::Vec2 org_anchor;
  149.     cocos2d::Vec2 org_pos;
  150.     cocos2d::Size org_size;
  151.     cocos2d::BlendFunc org_blend;
  152.     int32_t org_zorder;
  153.  
  154.  
  155.     frameData buf1;
  156.     frameData buf2;
  157.  
  158. public:
  159.     cocos2d::CustomCommand* _customCommand = nullptr;
  160.     cocos2d::Sprite* holdersprite = nullptr; //not actual holder
  161.  
  162.     bool shouldhide = false;
  163.     bool firstBuff = true;
  164. };
  165.  
  166. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement