Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3359966
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:56:12+00:00 2026-05-18T02:56:12+00:00

So I have a class. .h file with some variables like: struct AudioSample {

  • 0

So I have a class. .h file with some variables like:

  struct AudioSample
  { 
    const unsigned char * buffer;
      int len;
  };
        //...
      const unsigned char * VideoFrameBuffer;
      int VideoFrameLen;


  std::queue<AudioSample> AudioSamples;


  bool sampleSendingFinished;
  bool frameSendingFinished;
      //...

And .CPP file with functions

void VideoEncoder::UrlWriteData()
{
    while(1){
        if (AudioSamples.empty() && VideoFrameBuffer == NULL)
        {
            Sleep(1);
        }
        else if(!AudioSamples.empty())
        {
            struct AudioSample newAudioSample = AudioSamples.front();
            url_write (url_context, (unsigned char *)newAudioSample.buffer, newAudioSample.len);
        }
        else if (AudioSamples.empty() && VideoFrameBuffer != NULL)
        {
            url_write (url_context, (unsigned char *)VideoFrameBuffer, VideoFrameLen);
        }
    }

}
void VideoEncoder::AddSampleToQueue(const unsigned char *buf, int size )
{

    struct AudioSample newAudioSample;
    newAudioSample.buffer = buf;
    newAudioSample.len = size;
    AudioSamples.push(newAudioSample);
}
void VideoEncoder::AddFrameToQueue(const unsigned char *buf, int size )
{
    VideoFrameBuffer = buf;
    VideoFrameLen = size;
}

once in a while some functions call AddFrameToQueue and AddSampleToQueue. UrlWriteData lives in separete thread.
My app compiles. But my problem is – when I run it it dies on line:

        else if(!AudioSamples.empty())
        {
            struct AudioSample newAudioSample = AudioSamples.front();

Why it dies and how to make it not die?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:56:12+00:00Added an answer on May 18, 2026 at 2:56 am

    There is a thread-safe producer-consumer queue using soon-to-be standard threading mechanisms here. This would be a good intro to the threading concepts you have to understand to make this design work.

    The producer(s) are the functions that add to your queue, and the consumer(s) are the function(s) that read and (usually) process queue entries – UrlWriteData, here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an actionscript file that defines a class that I would like to
Lets say that i have a class with some instance variables and i want
I have several buttons that set some variables for another class (via extern). Thing
I have a class file that contains all the classes that are needed for
I have created a C# class file by using a XSD-file as an input.
I used to have one class for one file. For example car.cs has the
If I have a Java source file (*.java) or a class file (*.class), how
I have a class that parses very large file (that can't fit in memory)
I have a class isSearching with a single boolean property in a 'functions' file
I have a KMainWindow: //file.h class MainWindow: public KMainWindow { public: MainWindow(QWidget *parent =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.