Blame view

src/FrameQueue.cpp 1.52 KB
aac5773f   hucm   功能基本完成,接口待打磨
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
  #include "FrameQueue.h"
  
  FrameQueue::FrameQueue(/* args */)
  {
      for (size_t i = 0; i < Maxsize; i++)
      {
          base[i] = av_frame_alloc();
      }
  
  	front = rear = 0;//头指针和尾指针置为零,队列为空
  }
  
  FrameQueue::~FrameQueue()
  {
      if (base)
  	{
          for (size_t i = 0; i < Maxsize; i++)
          {
              if (base[i])
              {
                  av_frame_free(&base[i]);
              }
          }
  	}
  
      rear = front = 0;
  }
   
  //循环队列的入队
  AVFrame* FrameQueue::getTail()
  {
  	//插入一个元素eQ的新的队尾元素
  	if ((rear + 1) % Maxsize == front)
  		return nullptr;//队满
  	return base[rear];//获取队尾元素
  }
  
  // 将队尾元素添加到队列中
  void FrameQueue::addTail()
  {
       rear = (rear + 1) % Maxsize;//队尾指针加1
  }
   
  //循环队列的出队
  AVFrame* FrameQueue::deQueue()
  {
  	//删除Q的队头元素,用e返回其值
  	if (front == rear)
  		return nullptr;//队空
  	AVFrame* e = base[front];//保存队头元素
  	front = (front + 1) % Maxsize;//队头指针加1
  	return e;
  }
   
  //取循环队列的队头元素
  AVFrame* FrameQueue::getHead()
  {
  	//返回Q的队头元素,不修改队头指针
  	if (front == rear)
  		return nullptr;//队列为空,取元素失败
  	return base[front];
  }
  
  void FrameQueue::addHead()
  {
      front = (front + 1) % Maxsize;//队头指针加1
  }
  
  int FrameQueue::length()
  {
      return (rear - front + Maxsize) % Maxsize;
  }
  
  bool FrameQueue::isEmpty()
  {
  	if (front == rear)
  		return true;
  
  	return false;
  }
  
  void FrameQueue::clearQueue()
  {
  	rear = front = 0;
  }