c++ byteswriter

I am trying to write video data to a file.
The function that I want seems to be in an implementation file. I am not sure how to implement a function from an implementation file.

Here is the function i want to use:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
size_t CefBytesWriter::Write(const void* ptr, size_t size, size_t n) {
  base::AutoLock lock_scope(lock_);
  size_t rv;
  if (offset_ + static_cast<int64>(size * n) >= datasize_ &&
      Grow(size * n) == 0) {
    rv = 0;
  } else {
    memcpy(reinterpret_cast<char*>(data_) + offset_, ptr, size * n);
    offset_ += size * n;
    rv = n;
  }

  return rv;
}



When I put this in my implementation file I get the following error:

1
2
3
4
5
6
7
8
9
10
11
/home/c/Downloads/cef_binary_3.2704.1434.gec3e9ed_linux64/cefsimple/simple_handler.cc:40:1: error: ‘CefBytesWriter’ does not name a type
 CefBytesWriter::CefBytesWriter(size_t grow)
 ^
/home/c/Downloads/cef_binary_3.2704.1434.gec3e9ed_linux64/cefsimple/simple_handler.cc:49:1: error: ‘CefBytesWriter’ does not name a type
 CefBytesWriter::~CefBytesWriter() {
 ^
make[3]: *** [cefsimple/CMakeFiles/cefsimple.dir/simple_handler.cc.o] Error 1
make[2]: *** [cefsimple/CMakeFiles/cefsimple.dir/all] Error 2
make[1]: *** [cefsimple/CMakeFiles/cefsimple.dir/rule] Error 2
make: *** [cefsimple] Error 2



Here is the link to the class that includes the function I want to use:

https://bitbucket.org/chromiumembedded/cef/src/9ee4db6dbb3837cab08d25a35c1f86744c03bc32/libcef/browser/stream_impl.cc?at=master&fileviewer=file-view-default


I am not sure how to implement CefBytesWriter. what would I need to do in order to use that function.


I am able to use this in order to create a file:

CefRefPtr<CefStreamWriter> writer = CefStreamWriter::CreateForFile("this.txt");

but I cant use a pointer in order to get to the bytewriter
closed account (48bpfSEw)
What should the function do?


If you want to convert video formats
why don't you use https://ffmpeg.org/

?
thx, I thought about that. I am working on a media consumption application for Android. I basically need a lightweight webview that will allow the application to stream media in a popup window, one that plays above activities.

to get my own lightweight webview, Chromium embedded framework allows me to get the data, through blink i suppose, for the video from sites like you tube and then I want to steam them on a custom native surface view.

however, I am having trouble finding a way get the video data to the android native media player. I dont think ffmpeg can get the data from the sites like youtube, thats the issue. I am using Chromium Embedded by writing the data of a streaming video to a file. I am having the issue mentioned above.

Any suggestions are welcome. I am going about this in the wrong way you think? I hope the description was clear.
it seems like I can use CefStreamWriter. but im unable to use CEFbytesWriter. I know this is messy but how would I implement a byteswriter if I am unable to use a pointer and cannot override it in my header file.




Here is my current code:

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

CefRequestHandler::ReturnValue SimpleHandler::OnBeforeResourceLoad(
      CefRefPtr<CefBrowser> browser,
      CefRefPtr<CefFrame> frame,
      CefRefPtr<CefRequest> request,
      CefRefPtr<CefRequestCallback> callback)
{

CefRequest::ReferrerPolicy origin = REFERRER_POLICY_ALWAYS;
request->SetReferrer("https://www.google.com/",origin);
CefRefPtr<CefPostData> post_data = request->GetPostData();
 //if (post_data.get()) {
            CefPostData::ElementVector elements;
            post_data->GetElements(elements);
           // DLOG(INFO) << "size = " << elements.size();
           // if (elements.size() > 0) {
                CefPostData::ElementVector::const_iterator it = elements.begin();
	CefRefPtr<CefStreamWriter> writer = CefStreamWriter::CreateForFile("this.txt");
 		FILE *fd = fopen("this.txt", "w+b");
                size_t bytes_write = 0;
                for (; it != elements.end(); ++it) {
                    CefRefPtr<CefPostDataElement> element = (*it);
                    CefPostDataElement::Type type = element->GetType();
                    if (type == PDE_TYPE_BYTES) {
                        size_t size = element->GetBytesCount();
                        if (size > 0) {
                            char *bytes = new char[size];
                            element->GetBytes(size, bytes);

                            /* TODO FIXME: not work */
                            //int write = writer->Write(bytes, size, bytes_write);
//CefBytesWriter::CefBytesWriter(1);
//int CefBytesWriter::Write(bytes, 1, size);
                            
int write = writer->Write(bytes, 1, size);

                            bytes_write += write;
                            DLOG(INFO) << "write: size = " << size << ": " << std::string(bytes, size);

                            delete [] bytes;
                        }
                    } else if (type == PDE_TYPE_FILE) {
                        /* XXX: no use */
                        //element->GetFile();
                    }
                }
                //writer->Flush();
                fclose(fd);
         //   }
      //  }



//size_t size = 10;
//char *bytes = new char[10];
//size_t bytes_write = 0;
//CefRefPtr<CefStreamWriter> writer1 =
// writer->Write(bytes, 1, size);
 
//int write = writer->Write(bytes, size, bytes_write);
//                            int write = fwrite(bytes, 1, size, fd);


    return RV_CONTINUE;

}

Last edited on
maybe i can get the stream data with ffmpeg. thank you
seems like mpv may the best way to go. we will see
Topic archived. No new replies allowed.