Пример #1
0
Файл: tls.c Проект: aahud/harvey
void
main(void)
{
	int tube[2];
	int out, in;
	int i;

	pipe(tube);
	out = tube[0];
	in = tube[1];
	for(i = 0; i < Nproc; i++){
		pipe(tube);
		switch(rfork(RFPROC|RFMEM|RFFDG)){
		case -1:
			sysfatal("fork %r");
		case 0:
			close(tube[1]);
			copier(in, tube[0], Nloop);
			exits(nil);
		default:
			close(tube[0]);
			in = tube[1];
			break;
		}
	}
	write(out, "x", 1);
	copier(in, out, Nloop-1);
	close(out);
	for(i = 0; i < 8; i++)
		waitpid();
	exits(nil);
}
Пример #2
0
status_t
BAddressContactField::CopyDataFrom(BContactField* field)
{
	BAddressContactField::CopyVisitor copier(this);
	field->Accept(&copier);
	return copier.error;
}
Пример #3
0
//First call : chance_solver(dummy_grid,0,0,chance_grid); chance_grid=dummy_grid
//Recursive call : chance_solver(dummy_grid,x,y,new_chance_grid);
int chance_solver(int dummy_grid[MAX][MAX],int x, int y, int chance_grid[MAX][MAX])
{
	int i, contradiction;
       	int new_chance_grid[MAX][MAX], chance_array[MAX];
	if(dummy_grid[x][y] != 0){
		if(y == MAX - 1)
			chance_solver(dummy_grid,x+1,0,chance_grid);
	//	if(is_complete(chance_grid))
	//		print(chance_grid);
		else
			chance_solver(dummy_grid,x,y+1,chance_grid);
		return(0);
	}
	copier(chance_grid,new_chance_grid);
	contradiction = chance_updater(chance_grid,x,y,chance_array);
	if(contradiction)
		return FALSE;
	for(i = 0; i < MAX; ++i){
	       if(chance_array[i] == TRUE){
			new_chance_grid[x][y] = i + 1;
			if(is_complete(new_chance_grid))
				print(new_chance_grid);
	 		if(y == MAX - 1)
				chance_solver(dummy_grid,x+1,0,new_chance_grid);
			else
				chance_solver(dummy_grid,x,y+1,new_chance_grid);
	       }
	}
	return(0);
}
Пример #4
0
int main(int argc, char** argv)
{
	int orig_grid[MAX][MAX], dummy_grid[MAX][MAX];
	int iret, solved, unique, i, j;
	FILE *fp;
        if(argc != 2){
		printf("Usage : %s <Sudoku Input File>\n",argv[0]);
		exit(1);
	}
	fp = fopen(argv[1],"r");
	for(i = 0; i < MAX; i++){
		for(j = 0; j < MAX; j++){
			fscanf(fp,"%d ",&orig_grid[i][j]);
		}
	}
	unique = uniq_updater(orig_grid);
	printf("\n\nUniversal Sudoku Solver by Sushant Bhadkamkar\n\n");
	if(unique){
		printf("Unique solution Sudoku\n\n");
		print(orig_grid);
		return(0);
	}
	printf("Multiple solution sudoku\n\n");
	copier(orig_grid,dummy_grid);
	solved = chance_solver(dummy_grid,0,0,dummy_grid);
	return(0);
}
void XslCopyVisitor::visit(const MarkupNode& templte)
{
#ifdef XSL_TRANSFORM_TRACE
	clog << "XslCopy on MarkupNode" << endl;
#endif
	if (templte.ns() == NAMESPACE_APPLY_TEMPLATES && templte.name()
			== NAME_APPLY_TEMPLATES)
	{
#ifdef XSL_TRANSFORM_TRACE
		clog << "XslCopy - applying templates" << endl;
#endif
		CompositeMarkupNode::Children * newChildren = _transformer.transform(
				_parentProxy, *_referenceNode);
		if (newChildren != 0)
		{
			copy(newChildren->begin(), newChildren->end(), back_inserter(
					_result));
			delete newChildren;
		}
	}
	else
	{
		SimpleCopyVisitor copier(_transformer);
		_result.push_back(copier.copy(_parentProxy, templte));
	}
}
Пример #6
0
Файл: Main.cpp Проект: Bombe/tp
int Main::run() {
	Copier copier(stdin, stdout);

	copier.addCopierListener(this);
	copier.start();

	return 0;
}
//----------------------------------------------------- Méthodes protégées
void XslCopyVisitor::visit(const TextNode& templte)
{
#ifdef XSL_TRANSFORM_TRACE
	clog << "XslCopy on TextNode" << endl;
#endif
	SimpleCopyVisitor copier(_transformer);
	_result.push_back(copier.copy(_parentProxy, templte));
}
Пример #8
0
void sud::cherche(bool debug) {
    int ret, bon;
    int i, j, k;
    sud C;
    bool fini;

    while (!(ret = affecte(bon, debug))) {
        if (debug) {
            cerr << "bon : " << bon << endl;
            //affich();
        }
    }
    switch (ret) {
    case -1 :
        if (debug) {
            cerr << "Argh !" << endl;
        }
        break;
    case 1 :
        if (debug) {
            cerr << "Ok pas fini" << endl;
        }
        fini = false;
        for (i = 0; i < N && !fini; i++)
            for (j = 0; j < N; j++) {
                cerr << i << ':' << j << ':' << V[i][j] << " ! ";
                if (V[i][j] == 0) {
                    fini = true;
                    break;
                }
            }
        for (k = 0; k < N; k++)
            if (B[i][j][k]) {
                copier(C);
                C.V[i][j] = k + 1;
                C.simplif(i,j);
                if (debug) {
                    cerr << "trouve 5 : ";
                    cerr << "V[" << i << "][" << j<< "] = " << k + 1 << endl;
                    affich();
                    C.affich();
                }
                //C.affich();
                C.cherche(debug);
            }
        break;
    case 2 :
        if (debug) {
            cerr << "Ok fini" << endl;
            cerr << "bon : " << bon << endl;
            affich();
        }
        break;
    default :
        cerr << "???" << endl;
    }
    cerr << endl;
}
Пример #9
0
ESEnumerableModifyWnd::~ESEnumerableModifyWnd(){
	// Copy from list rowset into enumerable object. {{
	if( m_pList && m_pListRowSet && m_pEnumerable ){
		Serializable* pObject = m_pEnumerable->CreateSerializableObject();
		DataFieldCopier copier(m_pListRowSet, pObject, true); 
		m_pEnumerable->RemoveAll(true);
		copier.CopyFromVRowIntoEnumerable(m_pListRowSet, m_pEnumerable);
		}
	// }}
	}
status_t
BAddressContactField::CopyDataFrom(BContactField* field)
{
	status_t ret = BContactField::CopyDataFrom(field);
	if (ret != B_OK)
		return ret;

	BAddressContactField::CopyVisitor copier(this);
	field->Accept(&copier);
	return copier.error;
}
Пример #11
0
Tree::menuClicDroit::menuClicDroit(MainWindow *mainWindow)
{
    // Constructeur menu clic droit sur l'arborescence
    this->menu = new QMenu();
    this->nouveauSample = new QAction(trUtf8("Nouvel échantillon..."), this->menu);
    connect(this->nouveauSample, SIGNAL(triggered()), mainWindow, SLOT(importerSmpl()));
    this->menu->addAction(this->nouveauSample);
    this->nouvelInstrument = new QAction(trUtf8("Nouvel instrument..."), this->menu);
    connect(this->nouvelInstrument, SIGNAL(triggered()), mainWindow, SLOT(nouvelInstrument()));
    this->menu->addAction(this->nouvelInstrument);
    this->nouveauPreset = new QAction(trUtf8("Nouveau preset..."), this->menu);
    connect(this->nouveauPreset, SIGNAL(triggered()), mainWindow, SLOT(nouveauPreset()));
    this->menu->addAction(this->nouveauPreset);
    this->menu->addSeparator();

    // Remplacer / associer
    this->associer = new QAction(trUtf8("Associer à..."), this->menu);
    connect(this->associer, SIGNAL(triggered()), mainWindow, SLOT(associer()));
    this->menu->addAction(this->associer);
    this->remplacer = new QAction(trUtf8("Remplacer par..."), this->menu);
    connect(this->remplacer, SIGNAL(triggered()), mainWindow, SLOT(remplacer()));
    this->menu->addAction(this->remplacer);
    this->menu->addSeparator();

    // Copier / coller / supprimer
    this->copier = new QAction(trUtf8("Copier"), this->menu);
    this->copier->setShortcut(QString("Ctrl+C"));
    connect(this->copier, SIGNAL(triggered()), mainWindow, SLOT(copier()));
    this->menu->addAction(this->copier);
    this->coller = new QAction(trUtf8("Coller"), this->menu);
    this->coller->setShortcut(QString("Ctrl+V"));
    connect(this->coller, SIGNAL(triggered()), mainWindow, SLOT(coller()));
    this->menu->addAction(this->coller);
    this->supprimer = new QAction(trUtf8("Supprimer"), this->menu);
    this->supprimer->setShortcut(QString("Del"));
    connect(this->supprimer, SIGNAL(triggered()), mainWindow, SLOT(supprimerElt()));
    this->menu->addAction(this->supprimer);
    this->menu->addSeparator();

    // Renommer
    this->renommer = new QAction(trUtf8("Renommer..."), this->menu);
    this->renommer->setShortcut(Qt::Key_F2);
    connect(this->renommer, SIGNAL(triggered()), mainWindow, SLOT(renommer()));
    this->menu->addAction(this->renommer);
    this->menu->addSeparator();

    // Fermer
    this->fermer = new QAction(trUtf8("Fermer le fichier"), this->menu);
    this->fermer->setShortcut(QString("Ctrl+W"));
    connect(this->fermer, SIGNAL(triggered()), mainWindow, SLOT(Fermer()));
    this->menu->addAction(this->fermer);
}
Пример #12
0
int main(int argc, char** argv)
{
    unique_ptr<CObjectIStream> in(CObjectIStream::Open(eSerial_AsnText, "seq-entry-sample.asn"));
    unique_ptr<CObjectOStream> out(CObjectOStream::Open(eSerial_AsnText, "seq-entry-sample_output.asn"));
    CObjectStreamCopier copier(*in, *out);

    CObjectTypeInfo(CType<CSeq_annot>())
        .SetLocalCopyHook(copier, new CDemoHook());

    copier.Copy(CType<CSeq_entry>());

    return 0;
}
Пример #13
0
int main(int argc, char *argv[])
{
    if (argc != 3)
    {
        std::cerr << "Usage: " << argv[0] << " <source> <target>" << std::endl;
        return 1;
    }
    boost::asio::io_service io;
    std::filesystem::path source(argv[1]);
    std::filesystem::path target(argv[2]);
    file_copier copier(io, source, target);
    copier.get_io_service().run(); // FIXME: Workaround (should be io.run())
    return 0;
}
Пример #14
0
int main(int argc, char** argv)
{
    auto_ptr<CObjectIStream> in(CObjectIStream::Open(eSerial_AsnText, "if"));
    auto_ptr<CObjectOStream> out(CObjectOStream::Open(eSerial_AsnText, "of"));
    CObjectStreamCopier copier(*in, *out);

    CObjectTypeInfo(CType<CBioseq>())
        .FindMember("annot")
        .SetLocalCopyHook(copier, new CDemoHook());

    copier.Copy(CType<CBioseq>());

    return 0;
}
Пример #15
0
void exer7()
{
    std::vector<int> exercise;
    exercise.push_back(1);
    exercise.push_back(2);
    exercise.push_back(3);
    exercise.push_back(2);
    exercise.push_back(1);
    exercise.push_back(4);
    exercise.push_back(5);
    
    std::set<int> copier(exercise.begin(), exercise.end());
    std::cout << std::endl;
    std::copy(copier.begin(), copier.end(), std::ostream_iterator<int>(std::cout, " "));    
}    
Пример #16
0
TEST(MockComparatorCopierTest, customObjectWithFunctionCopier)
{
    MyTypeForTesting expectedObject(9874452);
    MyTypeForTesting actualObject(2034);
    MockFunctionCopier copier(myTypeCopy);
    mock().installCopier("MyTypeForTesting", copier);

    mock().expectOneCall("function").withOutputParameterOfTypeReturning("MyTypeForTesting", "parameterName", &expectedObject);
    mock().actualCall("function").withOutputParameterOfType("MyTypeForTesting", "parameterName", &actualObject);

    mock().checkExpectations();
    CHECK_EQUAL(9874452, *(expectedObject.value));
    CHECK_EQUAL(9874452, *(actualObject.value));

    mock().removeAllComparatorsAndCopiers();
}
void SkiaCanvas::setBitmap(const SkBitmap& bitmap) {
    SkCanvas* newCanvas = new SkCanvas(bitmap);

    if (!bitmap.isNull()) {
        // Copy the canvas matrix & clip state.
        newCanvas->setMatrix(mCanvas->getTotalMatrix());

        ClipCopier copier(newCanvas);
        mCanvas->replayClips(&copier);
    }

    // unrefs the existing canvas
    mCanvas.reset(newCanvas);

    // clean up the old save stack
    mSaveStack.reset(NULL);
}
Пример #18
0
bool LptaD3DDynamicBuffer::Add(lpta::LptaVertices *vertices, const lpta::INDICES &indices)
{
    if (!CanFit(*vertices, indices)) {
        return false;
    }

    void *vertexWriteBuffer;
    unsigned int vertexByteSize = ToStride(vertices->GetType()) * vertices->GetNumVertices();

    WORD *indexWriteBuffer;
    unsigned int indexByteSize = sizeof(WORD) * indices.size();
    unsigned int indexOffset = numIndices;

    WORD lockFlag = numVertices > 0? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD;

    if (!LockedBuffers(&vertexWriteBuffer, vertexByteSize, 
        &indexWriteBuffer, indexByteSize, lockFlag)) {

        // log error
        return false;
    }

    LptaD3DVertexCopier copier(vertices);

    copier.CopyToBuffer(vertexWriteBuffer, vertexByteSize);
    numVertices += vertices->GetNumVertices();

    for (unsigned int i = 0; i < indices.size(); ++i) {
        indexWriteBuffer[i] = static_cast<WORD>(indices.at(i)) + indexOffset;
    }
    numIndices += indices.size();

    vertexBuffer->Unlock();
    indexBuffer->Unlock();
    return true;

}
Пример #19
0
void render_loop(AppData& app_data)
{
	ResourceAllocator alloc;

	RaytracerTarget raytrace_tgt(app_data, alloc);

	RaytracerData raytrace_data(app_data);
	RaytracerResources raytrace_res(app_data, raytrace_data, alloc);

	Raytracer raytracer(app_data, raytrace_res);
	RaytraceCopier::Params copy_params;
	RaytraceCopier copier(app_data, raytrace_tgt);

	Renderer renderer(app_data, raytrace_tgt.tex_unit);
	Saver saver(app_data);

	unsigned face = 0;
	unsigned tile = 0;
	const unsigned tiles = app_data.tiles();


	while(true)
	{
		if(app_data.skip_face[face])
		{
			++face;
			continue;
		}

		if(app_data.verbosity > 0)
		{
			app_data.logstr()
				<< "Rendering cube face "
				<< face
				<< std::endl;
		}

		raytracer.Use(app_data);

		if(tile == 0)
		{
			raytrace_tgt.Clear(app_data);
			raytracer.InitFrame(app_data, face);
			renderer.InitFrame(app_data, face);
		}

		if(tile < tiles)
		{
			raytracer.BeginWork(app_data);
			raytracer.Raytrace(app_data, tile);
			raytracer.EndWork(app_data);

			copier.Copy(app_data, copy_params, raytracer, tile);

			renderer.Use(app_data);
			renderer.Render(app_data);

			glfwSwapBuffers();

			tile++;
		}
		else if(face < 6)
		{
			glfwSwapBuffers();
			saver.SaveFrame(app_data, raytrace_tgt, face);
			if(face < 5)
			{
				tile = 0;
				face++;
			}
			else break;
		}
		glfwPollEvents();

		int new_x, new_y;
		glfwGetWindowSize(&new_x, &new_y);
		if(new_x > 0)
		{
			app_data.render_width = unsigned(new_x);
		}
		if(new_y > 0)
		{
			app_data.render_height = unsigned(new_y);
		}

		if(glfwGetKey(GLFW_KEY_ESC))
		{
			glfwCloseWindow();
			break;
		}
		if(!glfwGetWindowParam(GLFW_OPENED))
		{
			break;
		}
	}
}
int main()
{
/* Variable and structure definitions. */
int sd, sd2, rc, length = sizeof(int);
int totalcnt = 0, on = 1;
char temp;
char buffer[BufferLength];
struct sockaddr_in serveraddr;
struct sockaddr_in their_addr;
 
fd_set read_fd;
struct timeval timeout;
timeout.tv_sec = 15;
timeout.tv_usec = 0;
 
/* The socket() function returns a socket descriptor */
/* representing an endpoint. The statement also */
/* identifies that the INET (Internet Protocol) */
/* address family with the TCP transport (SOCK_STREAM) */
/* will be used for this socket. */
/************************************************/
/* Get a socket descriptor */
if((sd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
perror("Server-socket() error");
/* Just exit */
exit (-1);
}
else
printf("Server-socket() is OK\n");
 
/* The setsockopt() function is used to allow */
/* the local address to be reused when the server */
/* is restarted before the required wait time */
/* expires. */
/***********************************************/
/* Allow socket descriptor to be reusable */
if((rc = setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on))) < 0)
{
perror("Server-setsockopt() error");
close(sd);
exit (-1);
}
else
printf("Server-setsockopt() is OK\n");
 
/* bind to an address */
memset(&serveraddr, 0x00, sizeof(struct sockaddr_in));
serveraddr.sin_family = AF_INET;
serveraddr.sin_port = htons(SERVPORT);
serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);
 
printf("Using %s, listening at %d\n", inet_ntoa(serveraddr.sin_addr), SERVPORT);
 
/* After the socket descriptor is created, a bind() */
/* function gets a unique name for the socket. */
/* In this example, the user sets the */
/* s_addr to zero, which allows the system to */
/* connect to any client that used port 3005. */
if((rc = bind(sd, (struct sockaddr *)&serveraddr, sizeof(serveraddr))) < 0)
{
perror("Server-bind() error");
/* Close the socket descriptor */
close(sd);
/* and just exit */
exit(-1);
}
else
    printf("Server-bind() is OK\n");
 
/* The listen() function allows the server to accept */
/* incoming client connections. In this example, */
/* the backlog is set to 10. This means that the */
/* system can queue up to 10 connection requests before */
/* the system starts rejecting incoming requests.*/
/*************************************************/
/* Up to 10 clients can be queued */
if((rc = listen(sd, 10)) < 0)
{
    perror("Server-listen() error");
    close(sd);
    exit (-1);
}
else
    printf("Server-Ready for client connection...\n");
 
/* The server will accept a connection request */
/* with this accept() function, provided the */
/* connection request does the following: */
/* - Is part of the same address family */
/* - Uses streams sockets (TCP) */
/* - Attempts to connect to the specified port */
/***********************************************/
/* accept() the incoming connection request. */
int sin_size = sizeof(struct sockaddr_in);
if((sd2 = accept(sd, (struct sockaddr *)&their_addr, &sin_size)) < 0)
{
    perror("Server-accept() error");
    close(sd);
    exit (-1);
}
else
    printf("Server-accept() is OK\n");
 
/*client IP*/
printf("Server-new socket, sd2 is OK...\n");
printf("Got connection from the f***ing client: %s\n", inet_ntoa(their_addr.sin_addr));
 
/* The select() function allows the process to */
/* wait for an event to occur and to wake up */
/* the process when the event occurs. In this */
/* example, the system notifies the process */
/* only when data is available to read. */
/***********************************************/
/* Wait for up to 



 seconds on */
/* select() for data to be read. */
FD_ZERO(&read_fd);
FD_SET(sd2, &read_fd);
rc = select(sd2+1, &read_fd, NULL, NULL, &timeout);
if((rc == 1) && (FD_ISSET(sd2, &read_fd)))
{

	/* Read data from the client. */
	totalcnt = 0;
 
	while(totalcnt < BufferLength)
	{
		/* When select() indicates that there is data */
		/* available, use the read() function to read */
		/* 100 bytes of the string that the */
		/* client sent. */
		/***********************************************/
		/* read() from client */
		rc = read(sd2, &buffer[totalcnt], (BufferLength - totalcnt));
	
		if(rc < 0)
		{
		    perror("Server-read() error");
		    close(sd);
		    close(sd2);
		    exit (-1);
		}
		else if (rc == 0)
		{
		    printf("Client program has issued a close()\n");
		    close(sd);
		    close(sd2);
		    exit(-1);
		}
		else
		{
		    totalcnt += rc;
		    printf("Server-read() is OK\n");
		}
		 
	}

}
else if (rc < 0)
{
    perror("Server-select() error");
    close(sd);
    close(sd2);
    exit(-1);
}
/* rc == 0 */
else
{
    printf("Server-select() timed out.\n");
    close(sd);
    close(sd2);
    exit(-1);
}
 

// CALL A FUNCTION WITH A BUFFER OVERFLOW VULNERABILITY
copier(buffer);

/* Shows the data */
printf("Received data from the f***ing client: %s\n", buffer);
 
/* Echo some bytes of string, back */
/* to the client by using the write() */
/* function. */
/************************************/
/* write() some bytes of string, */
/* back to the client. */
printf("Server-Echoing back to client...\n");
rc = write(sd2, buffer, totalcnt);
if(rc != totalcnt)
{
perror("Server-write() error");
/* Get the error number. */
rc = getsockopt(sd2, SOL_SOCKET, SO_ERROR, &temp, &length);
if(rc == 0)
{
    /* Print out the asynchronously */
    /* received error. */
    errno = temp;
    perror("SO_ERROR was: ");
}
else
    printf("Server-write() is OK\n");
 
close(sd);
close(sd2);
exit(-1);
}
 
/* When the data has been sent, close() */
/* the socket descriptor that was returned */
/* from the accept() verb and close() the */
/* original socket descriptor. */
/*****************************************/
/* Close the connection to the client and */
/* close the server listening socket. */
/******************************************/




close(sd2);
close(sd);

exit(0);
return 0;
}
Пример #21
0
	This& operator=( const InternalGraph<V, E, OEL, VL, EL>& g )
	{
		detail::Copier< typename InternalGraph<V, E, OEL, VL, EL>::GraphContainer, GraphContainer > copier(g.getGraph(), _graph);
		boost::copy_graph( g.getGraph(), _graph, boost::vertex_copy(copier).edge_copy(copier) );
		rebuildVertexDescriptorMap();
		return *this;
	}
Пример #22
0
void VStreamsUnit::_testStreamCopier() {
    // Test VStreamCopier. We'll copy between streams using the different
    // constructor and init forms, and verify the results.
    // We use {} scopes so we can force the lifetimes and re-use variable names.

    VMemoryStream   copierRawStream1;
    VBinaryIOStream copierIOStream1(copierRawStream1);
    VMemoryStream   copierRawStream2;
    VBinaryIOStream copierIOStream2(copierRawStream2);

    copierIOStream1.writeString("Here is a string to be stored in raw stream 1 and later copied into raw stream 2 for comparison purposes.");

    // Note that we are using a chunk size (64) smaller than the amount of data,
    // in order to check the behavior of iterating over the chunks.

    /* subtest scope */ {
        copierIOStream1.seek0();
        copierRawStream2.setEOF(0);
        VStreamCopier    copier(64, &copierRawStream1, &copierRawStream2);
        while (copier.copyChunk())
            { }
        VUNIT_ASSERT_TRUE_LABELED(copierRawStream1 == copierRawStream2, "stream copier construct raw->raw");
    }

    /* subtest scope */ {
        copierIOStream1.seek0();
        copierRawStream2.setEOF(0);
        VStreamCopier    copier(64, &copierIOStream1, &copierIOStream2);
        while (copier.copyChunk())
            { }
        VUNIT_ASSERT_TRUE_LABELED(copierRawStream1 == copierRawStream2, "stream copier construct io->io");
    }

    /* subtest scope */ {
        copierIOStream1.seek0();
        copierRawStream2.setEOF(0);
        VStreamCopier    copier(64, &copierRawStream1, &copierIOStream2);
        while (copier.copyChunk())
            { }
        VUNIT_ASSERT_TRUE_LABELED(copierRawStream1 == copierRawStream2, "stream copier construct raw->io");
    }

    /* subtest scope */ {
        copierIOStream1.seek0();
        copierRawStream2.setEOF(0);
        VStreamCopier    copier(64, &copierIOStream1, &copierRawStream2);
        while (copier.copyChunk())
            { }
        VUNIT_ASSERT_TRUE_LABELED(copierRawStream1 == copierRawStream2, "stream copier construct io->raw");
    }

    VStreamCopier    copier;

    copierIOStream1.seek0();
    copierRawStream2.setEOF(0);
    copier.init(64, &copierRawStream1, &copierRawStream2);
    while (copier.copyChunk())
        { }
    VUNIT_ASSERT_TRUE_LABELED(copierRawStream1 == copierRawStream2, "stream copier init raw->raw");

    copierIOStream1.seek0();
    copierRawStream2.setEOF(0);
    copier.init(64, &copierIOStream1, &copierIOStream2);
    while (copier.copyChunk())
        { }
    VUNIT_ASSERT_TRUE_LABELED(copierRawStream1 == copierRawStream2, "stream copier init io->io");

    copierIOStream1.seek0();
    copierRawStream2.setEOF(0);
    copier.init(64, &copierRawStream1, &copierIOStream2);
    while (copier.copyChunk())
        { }
    VUNIT_ASSERT_TRUE_LABELED(copierRawStream1 == copierRawStream2, "stream copier init raw->io");

    copierIOStream1.seek0();
    copierRawStream2.setEOF(0);
    copier.init(64, &copierIOStream1, &copierRawStream2);
    while (copier.copyChunk())
        { }
    VUNIT_ASSERT_TRUE_LABELED(copierRawStream1 == copierRawStream2, "stream copier init io->raw");

    VUNIT_ASSERT_EQUAL_LABELED(copier.numBytesCopied(), copierRawStream1.getEOFOffset(), "stream copier num bytes copied");
}
Пример #23
0
void execute(Option &opt)
{
    try {
        //mp4v2::impl::log.setVerbosity(MP4_LOG_VERBOSE3);
        mp4v2::impl::log.setVerbosity(MP4_LOG_NONE);
        mp4v2::impl::MP4File file;
        std::fprintf(stderr, "Reading MP4 stream...\n");
        if (opt.inplace)
            file.Modify(opt.src);
        else
            file.Read(opt.src, 0);
        std::fprintf(stderr, "Done reading\n");
        MP4TrackId trackId = file.FindTrackId(0, MP4_VIDEO_TRACK_TYPE);
        mp4v2::impl::MP4Track *track = file.GetTrack(trackId);
        // XXX
        TrackEditor editor(reinterpret_cast<MP4TrackX*>(track));
        opt.originalTimeScale = editor.GetTimeScale();
        if (opt.printOnly) {
            printTimeCodes(opt, editor);
            return;
        }
        editor.SetAudioDelay(opt.audioDelay);
        if (opt.compressDTS)
            editor.EnableDTSCompression(true);
        if (opt.ranges.size())
            editor.SetFPS(&opt.ranges[0], opt.ranges.size(),
                          opt.requestedTimeScale);
        else if (opt.timecodeFile || opt.modified()) {
            if (opt.timecodeFile)
                loadTimecodeV2(opt, editor.GetFrameCount() + 1);
            else {
                uint64_t off = editor.CTS(0);
                opt.timeScale = opt.originalTimeScale;
                for (size_t i = 0; i < editor.GetFrameCount() + 1; ++i)
                    opt.timecodes.push_back(editor.CTS(i) - off);
                if (opt.optimizeTimecode)
                    averageTimecode(opt);
            }
            if (opt.optimizeTimecode && convertToExactRanges(opt))
                editor.SetFPS(&opt.ranges[0], opt.ranges.size(),
                              opt.requestedTimeScale);
            else {
                rescaleTimecode(opt);
                editor.SetTimeCodes(&opt.timecodes[0],
                        opt.timecodes.size(),
                        opt.timeScale);
            }
        }
        if (opt.modified()) {
            editor.AdjustTimeCodes();
            editor.DoEditTimeCodes();
        }
        if (opt.inplace)
            file.Close();
        else {
            std::fprintf(stderr, "Saving MP4 stream...\n");
            MP4FileCopy copier(&file);
            copier.start(opt.dst);
            uint64_t count = copier.getTotalChunks();
            for (uint64_t i = 1; copier.copyNextChunk(); ++i) {
                std::fprintf(stderr, "\rWriting chunk %" PRId64 "/%" PRId64 "...",
                        i, count);
            }
        }
        std::fprintf(stderr, "\nOperation completed with no problem\n");
    } catch (mp4v2::impl::Exception *e) {
        handle_mp4error(e);
    }
}